大家好,我已经解决这个问题一段时间了。我正在尝试从xampp发送邮件。我已经浏览了这里发布的几个解决方案,但似乎没有一个仍然有效。需要有人给我指一个正确的方向。
所以在我的php.ini中
[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = user@gmail.com
sendmail_path = "'"C:'xampp'sendmail'sendmail.exe'" -t"
我还有sendmail_path="''"C:''xamplep''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=user@gmail.com
auth_password=123456
force_sender=shadidhaque2014@gmail.com
附言:我在sendmail.ini中只有上面的代码现在,对于php脚本,我有一些非常简单的东西:
$send=mail('rzs2009@yahoo.com', 'subject', 'blah blah blah');
if ($send) {
# code..
echo "yes";
}else
{
echo "no";
}
现在,每当我尝试运行程序时,我都会得到一个否定。所以没有发送任何电子邮件。我哪里可能出了问题。提前谢谢。
这样修改代码:
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/