Kyle Thomas Kyle Thomas - 1 month ago 6
PHP Question

mail() returns true but does not send

These are my headers:

$defaultHeaders = 'MIME-Version: 1.0' . "\r\n";
$defaultHeaders .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$defaultHeaders .= 'From: Kyote Productions <no-reply@' . $_SERVER['SERVER_NAME'] . '>' . "\r\n";
$this->headers = (!empty($headers)) ? $headers : $defaultHeaders;


These are my subject, message and recipient:

$this->subject = $subject;
$this->message = $message;
$this->to = $recipient;


I am sending the mail like this:

return mail($this->to, $this->subject, $this->message, $this->headers);


When I write a method to
var_dump()
all these results they look like this:

array(4) {
[0]=>
string(39) "x@outlook.com,z@gmail.com,"
[1]=>
string(18) "PHP Mailer by Kyle"
[2]=>
string(187) "<html><head><title>PHP Mailer by Kyle</title></head><body><img style="width: 100%; height: 200px;" src="http://wallpapercave.com/wp/Qom1Iwe.jpg"><br /><br />Test email baby!</body></html>"
[3]=>
string(112) "MIME-Version: 1.0
Content-type: text/html; charset=UTF-8
From: Kyote Productions <no-reply@kyoteprod.x10.mx>
"
}
1


Error reporting is on, but I receive no errors and it returns 1 when I run this:

echo (int)$obj->sendMail();

Answer

Do you have a mail server installed?

As per the php.net mail page: "It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination."

I'd also point out this question about sending mail with php, and this question about sending mail on linux.

You could also try using the PHPMailer class rather than rolling your own; it's pretty handy.