-1

i am working on Php mail script for may contact form, condition is returning TRUE, but i am not getting any email. solution plz!

       <?php

        //if "email" variable is filled out, send email
        if (isset($_POST['submit']))  {

        //Email information
        $admin_email = "address@gmail.com";
        $email = $_POST['email'];
        $comment = $_POST['comment'];
        $name = $_POST['name'];

        //send email
        mail($admin_email,$comment, "From:" . $email);
        print("DONE!");
        }else{
            echo("failed!");
        }

        ?>  

2 Answers2

0

Check by adding header with it and refer my code below that will help you further.

Check your port also if working.

Reference : http://php.net/manual/en/function.mail.php

$to      = 'abc@example.com';
$subject = 'subject';
$message = 'XYZ';
$headers = 'From: pqr@example.com' . "\r\n" .
    'Reply-To: web@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
Virb
  • 1,580
  • 1
  • 13
  • 23
0

There are a variety of reasons your script appears to not be sending emails. It's difficult to diagnose these things unless there is an obvious syntax error. Without one you need to run through the checklist below to find any potential pitfalls you may be encountering.

Make sure error reporting is enabled and set to report all errors

Error reporting is essential to rooting out bugs in your code and general errors that PHP encounters. Error reporting needs to be enabled to receive these errors. Placing the following code at the top of your PHP files (or in a master configuration file) will enable error reporting.

 error_reporting(-1);
 ini_set('display_errors', 'On');
 set_error_handler("var_dump");

Make sure all mail headers are supplied

Some spam software will reject mail if it is missing common headers such as "From" and "Reply-to":

 $headers = array("From: from@example.com",
"Reply-To: replyto@example.com",
"X-Mailer: PHP/" . PHP_VERSION
);
$headers = implode("\r\n", $headers);
mail($to, $subject, $message, $headers);
Make sure mail headers have no syntax errors

Invalid headers are just as bad as having no headers. One incorrect character could be all it takes to derail your email. Double-check to make sure your syntax is correct as PHP will not catch these errors for you.

 $headers = array("From from@example.com", // missing colon
"Reply To: replyto@example.com",      // missing hyphen
"X-Mailer: "PHP"/" . PHP_VERSION      // bad quotes
 );

Make sure the recipient value is correct

Sometimes the problem is as simple as having an incorrect value for the recipient of the email. This can be due to using an incorrect variable.

 $to = 'user@example.com';

// other variables .... mail($recipient, $subject, $message, $headers); // $recipient should be $to Another way to test this is to hard code the recipient value into the mail() function call:

  mail('user@example.com', $subject, $message, $headers); 
Ajay Malhotra
  • 1,645
  • 2
  • 13
  • 16