电子邮件未从localhost接收

时间:2016-07-10 15:58:12

标签: php email

我正在尝试从localhost发送邮件到我的Gmail。我正在使用Windows 7.我的mail()函数在提交时没有显示任何错误。相反,在提交时,即使我无法正常看到窗口,也会出现一个窗口并突然消失。

mail.php

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

if(mail($to, $subject, $body,$headers))
{
    echo 'Mail has send';

}

else
{
        echo "Email Not Found";
}

的php.ini

1130 [mail function]
1131 ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
1132 SMTP = smtp.gmail.com
1133 smtp_port = 587
1134 sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

sendmail.ini

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=mygmail.com
auth_password=myPass
force_sender=mygmailgmail.com

2 个答案:

答案 0 :(得分:0)

初始化mail.php中的所有变量 这是一个例子:

$to       = 'sender_email_id_here@gmail.com';
$subject  = 'Testing';
$message  = 'Email Testing';
$headers  = 'From: your_emil_id_here@gmail.com' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Content-type: text/html; charset=utf-8';

答案 1 :(得分:0)

因为谷歌保持你的电子邮件安全,你的PHP应用程序或网站是不安全的谷歌的观点。可能是谷歌没有给你的PHP代码访问您的电子邮件。你可能要检查它。这是谷歌声明下面你可以看到 **

  • 安全性较低的应用访问

** 查看所选用户是否可以访问安全性较低的应用程序。您可以转到安全>来启用对安全性较低的应用程序的访问权限基本设置>安全性较低的应用访问并点击启用。访问权限由组织单位和组过滤器分配,而不是由用户

分配

屏幕截图,

enter image description here

相关问题