【发布时间】:2018-02-07 05:15:32
【问题描述】:
已经 3 天了,有同样的问题,我需要发现我的代码,我的代码返回失败,这是我在 sendmail.ini 中的 localhost 配置,这里是设置:
[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
我改变了我的 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"
这是我的 php 代码:
<?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" . "\r\n";
//$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers = array("From: xxx@gmail.com",
"Reply-To: " .$name. " <".$email.">",
"X-Mailer: PHP/" . PHP_VERSION
);
$headers = implode("\r\n", $headers);
$test = mail($to, $subject, $message, $headers);
if($test)
{
echo "Email sent successfully !!";
}
else
{
echo "fail!";
}
?>
【问题讨论】:
-
改用phpmailer
-
它也不起作用,我试过了,但我遇到了一些错误..
-
@AshryRamadhan,请您提供完整的错误消息。这样我才能理解您的实际问题。
-
@AmitSenjaliya - 像这样使用 PHPMailer,无法发送消息。Mailer 错误:SMTP 连接()失败。
-
我认为下面的答案会对您有所帮助。您是否启用了您的 gmail 以用作 smtp 服务器?