My php seems okay, but emails won't send.

okay, so i threw this php in my public_html (i don’t know if that’s where it goes) but the forms fill out okay, and i never get the email.
here’s the contact page:
[php]

Balkan Express

Contact Us!
Balkan Express

Contact

First Name

Last Name

Email

Phone

Message

BECOME PART OF THE FAMILY! DRIVE WITH US!
Balkan Express&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp #3 Crafton Sq. Pittsburgh, PA 15205 &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 800.223.8973&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp [email protected]

here’s the “behind the scenes part”

<?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "BALKAN SITE REQUEST"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.
'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.
'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?>

Thank you for contacting us. We will be in touch with you very soon.

<?php } ?>

[/php]

… so why isn’t it sending me an email when i fill it out?
it gets to the “thank you” part… but doesn’t take action

Where did you get this code? It looks like it was written in the 90’s. You can start with removing the @ error suppression from the mail function and turning on error reporting. Using tables for layout went out 20 years ago. You need to use CSS. And don’t create variables for nothing.

You could use something other than the mail function. It could be that it is sent, but you never see it. It could also be your server doesn’t have a mail client. It could also be that you never check IT was sent in the first place. It could be a number of things.

I just switched over to swiftmailer and here’s a testing script that I was working on ->

[php]<?php
include_once ‘vendor/swiftmailer/swiftmailer/lib/swift_required.php’;
include ‘config.php’;
$server_name = filter_input(INPUT_SERVER, ‘SERVER_NAME’, FILTER_SANITIZE_URL);
/* Setup swiftmailer using your email server information */
if (filter_input(INPUT_SERVER, ‘SERVER_NAME’, FILTER_SANITIZE_URL) == “localhost”) {
$transport = Swift_SmtpTransport::newInstance(EMAIL_HOST, EMAIL_PORT); // 25 for remote server 587 for localhost:
} else {
$transport = Swift_SmtpTransport::newInstance(EMAIL_HOST, 25);
}

$transport->setUsername(EMAIL_USERNAME);
$transport->setPassword(EMAIL_PASSWORD);

/* Setup To, From, Subject and Message */
$message = Swift_Message::newInstance();

$submit = htmlspecialchars($_POST[‘submit’]);
if (isset($submit) && $submit === “submit”) {

$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$subject = filter_input(INPUT_POST, 'reason', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$email_from = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$comments = filter_input(INPUT_POST, 'comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

/* Person or people to send email to */
$message->setTo([
    '[email protected]'
]);

$message->setSubject($subject); // Subject:
$message->setBody($comments); // Message:
$message->setFrom($email_from, $name); // From and Name:

$mailer = Swift_Mailer::newInstance($transport); // Setting up mailer using transport info that was provided:
$result = $mailer->send($message, $failedRecipients);

if ($result) {
    header("Location: email.php");
    exit();
} else {
    echo "<pre>" . print_r($failedRecipients, 1) . "</pre>";
}

}
?>

Email Demo
        <fieldset>

            <legend><?php echo (isset($errMessage)) ? $errMessage : 'Contact Details'; ?></legend>

            <label for="name" accesskey="U">Your Name</label>
            <input name="name" type="text" id="name" placeholder="Enter your name" required="required" />

            <label for="email" accesskey="E">Email</label>
            <input name="email" type="email" id="email" placeholder="Enter your Email Address"  required="required" />

            <label for="phone" accesskey="P">Phone <small>(optional)</small></label>
            <input name="phone" type="tel" id="phone" size="30" placeholder="Enter your phone number" />

            <label for="website" accesskey="W">Website <small>(optional)</small></label>
            <input name="website" type="text" id="website" placeholder="Enter your website address" />

        </fieldset>

        <fieldset>

            <legend>Your Comments</legend>

            <div class="radioBlock">
                <input type="radio" id="radio1" name="reason" value="support" checked>
                <label class="radioStyle" for="radio1">support</label>
                <input type="radio" id="radio2" name="reason" value="advertise">
                <label class="radioStyle" for="radio2">advertise</label>  
                <input type="radio" id="radio3" name="reason" value="error">
                <label class="radioStyle" for="radio3">Report a Bug</label>    
            </div>

            <label class="textBox" for="comments">Comments</label>
            <textarea name="comments" id="comments" placeholder="Enter your comments" spellcheck="true" required="required"></textarea>             

        </fieldset>

        <input type="submit" name="submit" value="submit">

    </form>
</body>
[/php]

Here’s the emailstyle.css file contents :

[code]* {
box-sizing: border-box;
}

body {
background-color: #aec4de;
padding: 0;
margin: 0;
}

div.header {
display: block;
width: 100%;
max-width: 800px;
height: 150px;
background-color: #ebdb8d;
padding: 0;
margin: 20px auto;
}

div.header h1 {
font-family: “Palatino Linotype”, “Book Antiqua”, Palatino, serif;
font-size: 3.2rem;
line-height: 150px;
color: #2e2e2e;
text-align: center;
}

form#contact {
display: block;
width: 100%;
max-width: 500px;
height: auto;
background-color: antiquewhite;
padding: 20px;
margin: 5px 0 20px 20px;
}

form#contact fieldset {
border: 2px solid #2e2e2e;
padding: 30px;
margin-bottom: 20px;
}

form#contact fieldset legend {
font-family: “Palatino Linotype”, “Book Antiqua”, Palatino, serif;
font-size: 1.4rem;
color: #2e2e2e;
padding: 0 5px;
}

form#contact fieldset label {
float: left;
display: block;
width: 100%;
max-width: 150px;
height: 25px;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.02rem;
line-height: 25px;
color: #2e2e2e;
text-align: right;
padding: 0 10px;
}

form#contact fieldset input {
clear: right;
display: block;
width: 100%;
max-width: 200px;
height: 25px;
border: none;
outline: none;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.0rem;
color: #2e2e2e;
padding: 0 5px;
margin-bottom: 10px;
}

form#contact fieldset .radioBlock {
display: block;
width: 100%;
max-width: 100%;
height: auto;
margin: 0 auto;
}

form#contact fieldset input[type=radio] {
display: none;
margin: 10px;
}

form#contact fieldset input[type=radio] + label.radioStyle {
display: inline-block;
width: 33.33333333333%;
height: 45px;
margin: -2px;
text-align: center;
text-transform: capitalize;
cursor: pointer;
color: #fff;
background-color: #000;
border: 2px solid #ffa;
line-height: 45px;
margin: 10px auto 0 auto;
}

form#contact fieldset input[type=radio] + label.radioStyle:hover {
background-color: #aaa;
color: #ffa;
}

form#contact fieldset input[type=radio]:checked + label.radioStyle {
background-image: none;
color: #ffa;
background-color: #aaa;
}

form#contact fieldset label.textBox {
clear: both;
text-align: left;
padding: 0;
margin-top: 20px;
}

form#contact fieldset textArea#comments {
resize: none;
border: none;
outline: none;
clear: both;
display: block;
width: 100%;
max-width: 660px;
height: 300px;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.2rem;
padding: 10px;
}

form#contact input[type=submit] {
outline: none;
border: none;
display: block;
width: 100%;
max-width: 120px;
height: 40px;
cursor: pointer;
background-color: #000;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.2rem;
color: #fff;
text-transform: capitalize;
margin-left: 340px;
}

form#contact input[type=submit]:hover {
color: #ffa;
background-color: #aaa;
}[/code]

HTH - John

Sponsor our Newsletter | Privacy Policy | Terms of Service