Skip to content Skip to sidebar Skip to footer

PHP Contact Form Submitting But Not Receiving Email

I realise this question has been asked numerous times before but everyone's code is obviously different and I am quite new to php so just looking to see if someone can give me some

Solution 1:

You have used sessions which is not required here, you can also use flag variable instead of arrays in this simple form, use this updated code.

<?php
//$to_mail = "architects@palavin.com,t.lavin@palavin.com,12yorkcourt@gmail.com";
$to_mail = "danny@enhance.ie";
//$cc="paul@enhance.ie";
$mail_sent = 0;
if(isset($_POST['submit'])){
    //echo "the form was submitted";

$name = trim(strip_tags($_POST['name']));
if($name == "")
    $error = true;

$email = trim(strip_tags($_POST['email']));
if($email == "")
    $error = true;

$phone = trim(strip_tags($_POST['phone']));
$address = trim(strip_tags($_POST['address']));
$description = trim(strip_tags($_POST['description']));


if($error != true){
    $headers = 'From: "Euro Insulation" <no-reply@euroinsulations.ie>'."\r\n";
    //$headers .= 'CC: "'.$cc.'" <'.$cc.'>'."\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "";

    $subject = "New contact message";

    $message = "New Contact message, received from: <br /> \n ";
    $message .= "<b>Name</b> ".$name."<br /> \n";
    $message .= "<b>Email</b> ".$email."<br /> \n";

    $message .= "<b>Phone</b> ".$phone."<br /> \n";
    $message .= "<b>Address</b> ".$address."<br /> \n";

    $message .= "<b>Description</b> ".$description."<br /> \n";

    if(@mail($to_mail,$subject,$message,$headers))
    {
        echo "mail sent";
        $mail_sent = 1;
    }
    else echo "mail not sent";
} else {
    echo 'validation error';
}
}
?> 

You have also missed out the else statement for your form validation test so no errors getting displayed when you submit form.


Solution 2:

Remove the at sign from mail function and see what errors your get. @mail suppresses errors from being displayed.


Solution 3:

Comment out the following line: if ( isset($SESSION['code']) && $SESSION['code'] == strtoupper($str)){} else {$error['secu'] = 1;}

You should be able to reach the mail function.


Post a Comment for "PHP Contact Form Submitting But Not Receiving Email"