Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail() function sucess, but didn't receive any email

Tags:

php

I'm try to sent email by my localhost php, but the problem is i didn't receive anything in my email, what should i configure?

Here is my code

$to="[email protected]";
$name="jason";
$subject="test message";
$header="From: $name";
$message="blah blah blah";
$sentmail=mail($to,$subject,$message,$header);

echo $sentmail ? "email send" : "email send fail"?

as the result was "email send"

like image 366
Jason Kuah Avatar asked Jul 25 '13 04:07

Jason Kuah


2 Answers

There are 2 reason not to send email from your localhost..

  1. You don't have mail server setup in your local environment
  2. You are not using SMTP service to send the email.

So either you have to configure the mail server but I don't think that this is a handy solution.

Better you try to use SMTP service. To do this it will be better if your use PHPMailer.

Here is an example using PHPMailer class.

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';

$mail->Host       = "mail.example.com"; // SMTP server example
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "username"; // SMTP account username example
$mail->Password   = "password"; 

You can use this class for any kind of email as a alternative of PHP : mail().

like image 97
S. Rasel Avatar answered Sep 25 '22 16:09

S. Rasel


mail function will Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

mail function will not check whether mail reached in your inbox

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

You can't check whether mail has been delivered, but you can check whether the recipients opened your mail with tracking pixel https://support.google.com/dfp_premium/answer/1347585?hl=en

like image 32
Miqdad Ali Avatar answered Sep 22 '22 16:09

Miqdad Ali