dqhsv0147421 2018-02-07 05:15
浏览 86

PHP失败发送电子邮件,xampp localhost服务器[重复]

This question already has an answer here:

it was 3 days, have the same problem, i need to spot my code, i got fail return with my code, this is my localhost configuration in, sendmail.ini, here the setting:

[sendmail]

smtp_server = smtp.gmail.com
smtp_port = 587
smtp_ssl = auto
error_logfile = error.log
debug_logfile = debug.log
auth_username = xxx@gmail.com
auth_password = xxx
force_sender = xxx@gmail.com

and i change my php.ini:

[mail function]

SMTP=smtp.gmail.com

smtp_port=587

sendmail_from = xxx@gmail.com

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

this is my php code :

<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");

$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['message'];

$to=$email;

//$headers = "MIME-Version: 1.0" . "
";
//$headers .= "Content-type:text/html;charset=iso-8859-1" . "
";

$headers = array("From: xxx@gmail.com",
    "Reply-To: " .$name. " <".$email.">",
    "X-Mailer: PHP/" . PHP_VERSION
);

$headers = implode("
", $headers);

$test = mail($to, $subject, $message, $headers);
if($test)
{
echo "Email sent successfully !!";    
}
else
{
echo "fail!";
}
?>
</div>
  • 写回答

1条回答 默认 最新

  • dongzan2740 2018-02-07 06:05
    关注

    you should follow following step, It will help

    1. Login to your Google account.
    2. Go to the 'My Account' page and click Sign-in & security.
    3. turn On Allow less secure apps.

    Thanks for explaining your error message.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画