【问题标题】:PHPMailer isn't workingPHPMailer 不工作
【发布时间】:2016-08-25 08:22:51
【问题描述】:

require_once('class.phpmailer.php');
$mail = new PHPMailer();

$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure="tls";
$mail->Host = "smtp.mail.yahoo.com";
$mail->Port = 587;
$mail->Username = "********@yahoo.com";
$mail->Password = "*****";

$mail->SetFrom('*********@yahoo.com', 'my name');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML('text');
$mail->AddAddress('*********@yahoo.com', 'my name');

if($mail->Send()) {
    echo "Message sent!";
}else {
    echo "Mailer Error: " . $mail->ErrorInfo;
}

所以,我尝试使用 PHPMailer 发送一封电子邮件,但它的代码不起作用,本地主机页面不起作用。我将 class.phpmailer.php 和 class.smtp.php 复制到 /var/www/html 文件夹(在我在 require_once (/usr/share/...) 中指定路径之前)。我启用了 ssl 扩展。我使用 Ubuntu 16.04 并安装了 libphp-phpmailer。我该怎么办? (任何使用 smtp 发送邮件的选项都会受到重视,已经尝试过:postfix 和 sendmail)。

【问题讨论】:

  • “不工作”、“不工作”对于说明发生了什么是没有用的。看起来您使用的是非常旧版本的 PHPMailer,所以get the latest

标签: phpmailer


【解决方案1】:

通过上面的评论链接..!!

试试这个

<?php
include "PHPMailer_5.2.4/class.phpmailer.php"; 
$mail = new PHPMailer(); 

$mail->IsSMTP(); 
$mail->SMTPDebug = 1; 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "smtp.gmail.com";

$mail->Port = 465; 
$mail->IsHTML(true);
$mail->Username = "******@gmail.com";
$mail->Password = "*******";

$mail->SetFrom('aswad@yahoo.com', 'my name');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML('text');
$mail->AddAddress('aswad@yahoo.com', 'my name');

if($mail->Send()) {
    echo "Message sent!";
}else {
    echo "Mailer Error: " . $mail->ErrorInfo;
}
?>

【讨论】:

    【解决方案2】:

    尝试评论

    $mail->IsSMTP();
    

    还要检查 SELinux 配置

    关于外壳类型

    sestatus -b | grep 发送邮件

    如果你看到了 httpd_can_sendmail 关闭

    只需输入这 2 行:

    1. restorecon /usr/sbin/sendmail
    2. setsebool -P httpd_can_sendmail 1

    【讨论】:

      猜你喜欢
      • 2014-03-14
      • 1970-01-01
      • 2012-05-21
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多