Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail() doesn't work [duplicate]

Tags:

php

email

I want to script a simple registration form with activation mail and so on. But for some reason mail() doesn't send the emails, or my 3 different email accounts (hotmail,gmail,yahoo) don't receive them and therefore don't even put them in the spam folder.

Code:

<?php
    $mailto = '[email protected]';
    $subject = 'the subject';
    $message = 'the message';
    $from = '[email protected]';
    $header = 'From:'.$from;

    if(mail($mailto,$subject,$message,$header)) {
        echo 'Email on the way';
    }
?>

Everytime it outputs 'Email on the way' so mail() returns true, right? I really don't get it, I've even tried to turn off my little snitch (although I didn't block SMTP).

like image 660
Rivers Avatar asked Jun 19 '11 16:06

Rivers


3 Answers

See this article by Jeff Atwood.

In short: Just because your code has handed the e-mail to a Mail Transfer Agent, it doesn't mean it will be delivered. Yes, mail() returning true means "accepted for delivery" - which means "Looks like an e-mail, I'll try to deliver this", not "It is delivered". Even the manual for mail() says:

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.

Soooo: check your MTA (is the e-mail sent from your local computer?), try to send to a local address (if the address is local, does it get delivered?), try to send an e-mail from your mail client, using the same settings as your PHP script, try to send to a smaller mail-hoster which allows you tu switch off antispam (is it delivered outside your network?). Also, read that article, and check the points mentioned there.

like image 190
Piskvor left the building Avatar answered Oct 20 '22 04:10

Piskvor left the building


Maybe your server is not configured to handle mail().

<?php
    print phpinfo();  
?>

and look at sendmail_path

like image 20
DENIEL Avatar answered Oct 20 '22 02:10

DENIEL


You may need to add correct end of line characters to the Headers. It may be \n or \r\n

like image 30
Brombomb Avatar answered Oct 20 '22 04:10

Brombomb