[英]MAMP PHP Mailer Not Working
我無法使phpmailer與MAMP(免費版)一起使用。 我曾嘗試過與他人合作的一些建議,但我沒有運氣。
這些是我到目前為止嘗試過的:1)嘗試使用php使用常規郵件功能-http: //www.blog.tripleroi.com/2012/05/solvedenabling-sendmail-on-localhost.html
2)按照這些發布說明啟用了postfix- 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';
}
修復。 在/etc/postfix/main.cf上,我添加了以下內容:smtp_sasl_security_options = noanonymous smtp_sasl_mechanism_filter = plain relayhost = smtp.live.com:587至最低的postfix配置。 然后使用我的實時服務器憑據修改sasl_passwd文件,然后重新加載后綴。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.