du521521521 2018-06-28 05:42
浏览 18
已采纳

PHP邮件功能在服务器上不起作用[重复]

This question already has an answer here:

I recently shifted my servers and found that default PHP mail function is not working which was working in the previous server. I tested it by writing simple mail function

$mailto="me@domain.com";  //Enter recipient email address here

$subject = "Test Email";

$from="you@domain.com";          //Your valid email address here

$message_body = "This is a test email from Webmaster.";

$mail =   mail($mailto,$subject,$message_body,"From:".$from);
var_dump($mail);
if($mail) {
    echo "Your email has been sent successfully";
} else {
    echo "not sent";
}

Above code return me false value. I googled it. checked my PHP.ini. It is also set as the solution mentioned in the google links.

; For Win32 only. 

; http://php.net/sendmail-from

;sendmail_from =me@example.com

; For Unix only.  You may supply arguments as well
(default: "sendmail -t -i").  
; http://php.net/sendmail-path

sendmail_path = "/usr/sbin/sendmail -t -i"

I don't what I am missing.

</div>
  • 写回答

2条回答 默认 最新

  • dongyan2469 2018-06-28 06:37
    关注

    It returns FALSE, it means there is a problem with your mail configuration. You would need to check the mail log to see if you are getting any errors. The kicker is that php may be handing off the mail, your server may be sending off the mail, and it may get spam filtered along the way.

    <?php 
        mail('nobody@example.com', 'the subject', 'the message', null, '-fwebmaster@example.com'); 
    ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?