Kyle Thomas Kyle Thomas - 3 years ago 107
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
all these results they look like this:

array(4) {
string(39) ",,"
string(18) "PHP Mailer by Kyle"
string(187) "<html><head><title>PHP Mailer by Kyle</title></head><body><img style="width: 100%; height: 200px;" src=""><br /><br />Test email baby!</body></html>"
string(112) "MIME-Version: 1.0
Content-type: text/html; charset=UTF-8
From: Kyote Productions <>

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

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

Answer Source

Do you have a mail server installed?

As per the 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download