我无法让phpmailer使用MAMP(免费版)。我已经尝试过其他人的一些建议,但是我没有运气。
这是我到目前为止所尝试的: 1)试图使用这个 - http://www.blog.tripleroi.com/2012/05/solvedenabling-sendmail-on-localhost.html
从php使用常规邮件功能2)按照这些发布说明启用后缀 - http://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-mountain-lion/(已收到“未发送邮件返回发件人”)
我刚刚使用通用脚本进行测试,但它仍然失败(但消息显示“成功”或“消息已发送”)。
脚本1:
$to = '<user>@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: <user>@yahoo.com' . "\r\n" .
'Reply-To: <user>@yahoo.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$retval = mail($to, $subject, $message, $headers);
if($retval !== true) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
脚本2:
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 2; // Enable verbose debug output
echo "<pre>";
$mail->isSMTP(); // Set mailer to use SMTP
echo "</pre>";
$mail->Host = 'smtp.mail.yahoo.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '<user>@yahoo.com'; // SMTP username
$mail->Password = '<password>'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom('<user>@yahoo.com', 'Mailer');
$mail->addAddress('<user1>@yahoo.com', 'Joe User'); // Add a recipient
$mail->addAddress('<user2>@live.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
答案 0 :(得分:0)
修正了它。在/etc/postfix/main.cf上,我添加了以下内容:smtp_sasl_security_options = noanonymous smtp_sasl_mechanism_filter = plain relayhost = smtp.live.com:587到最小后缀配置。然后使用我的实时服务器凭据修改sasl_passwd文件,然后重新加载postfix。