php发送电子邮件不起作用

时间:2018-06-13 12:50:34

标签: php email gmail phpmailer

我正在使用XAMPP版本:1.8.3 当我测试页面时我没有收到任何错误,mail()函数返回false。 我的代码如下。

<?php

try {
    $to = "***@gmail.in";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "***@gmail.com";
    $headers = "From:" . $from;
    $res = mail($to, $subject, $message, $headers);

    if ($res) {
        echo "<h4>Mail Sent.</h4>";
    } else {
        var_dump($res);
        echo "<h3>Mail not sent...</h3>";
    }
} catch (Exception $ex) {
    print_r($ex);
}
?>

sendmail.ini文件更改

hostname=localhost
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
auth_username=****@gmail.com
auth_password=****
force_sender=****@gmail.com

php.ini文件更改

SMTP = smtp.gmail.com
smtp_port = 587
sendmail_from = ***@gmail.com
sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\" -t"
;sendmail_path="D:\xampp\mailtodisk\mailtodisk.exe"

0 个答案:

没有答案