简体   繁体   English

MAMP PHP Mailer不起作用

[英]MAMP PHP Mailer Not Working

I can't get phpmailer to work with MAMP (Free version). 我无法使phpmailer与MAMP(免费版)一起使用。 I've tried some suggestions from others for what worked with them but I've had no luck. 我曾尝试过与他人合作的一些建议,但我没有运气。

These are what I've tried so far: 1) Tried to use regular mail function from php using this - http://www.blog.tripleroi.com/2012/05/solvedenabling-sendmail-on-localhost.html 这些是我到目前为止尝试过的:1)尝试使用php使用常规邮件功能-http: //www.blog.tripleroi.com/2012/05/solvedenabling-sendmail-on-localhost.html

2) Enabled postfix following these post instructions - http://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-mountain-lion/ (Been getting "Undelivered Mail Returned to Sender") 2)按照这些发布说明启用了postfix- http://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-mountain-lion/ (收到“未送达的邮件已退回发件人”)

I've just used generic scripts to tests and it keeps failing (but message says "success" or "Message has been sent"). 我刚刚使用了通用脚本进行测试,但该脚本一直失败(但是消息显示“成功”或“消息已发送”)。

Script 1: 脚本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';
}

Script 2: 脚本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';
}

Fixed it. 修复。 On the /etc/postfix/main.cf, I've added these: smtp_sasl_security_options=noanonymous smtp_sasl_mechanism_filter=plain relayhost=smtp.live.com:587 to the minimum postfix configurations. 在/etc/postfix/main.cf上,我添加了以下内容:smtp_sasl_security_options = noanonymous smtp_sasl_mechanism_filter = plain relayhost = smtp.live.com:587至最低的postfix配置。 Then revised the sasl_passwd file with my live server credentials and then reloaded postfix. 然后使用我的实时服务器凭据修改sasl_passwd文件,然后重新加载后缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM