【问题标题】:sending mail using smtp phpmailer doesn't work使用 smtp phpmailer 发送邮件不起作用
【发布时间】:2014-09-03 17:09:22
【问题描述】:

我在使用 PHPMailer 类发送电子邮件时遇到问题,在提交表单后,我收到了一封邮件发送正常,但我没有收到任何邮件。

我猜问题出在 SMTP 身份验证上,但我找不到问题。源应用程序存储在远程服务器中,IP 地址为:175.2.3.69,我使用 Outlook 计数发送邮件

有问题的代码是:

require_once('../libs/PHPMailer/class.phpmailer.php');
//Ensuite on débute l'envoi de mail

$mail = new PHPmailer();
$mail->IsSMTP(); // telling the class to use SMTP

try {
    $mail->Host       = "messagerie.abc.a.fr"; // SMTP server
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Port       = 25;                    // set the SMTP port for the GMAIL server
    $mail->Username   = "username.name@a-bc.fr"; // SMTP account username
    $mail->Password   = "password";        // SMTP account password
    $mail->AddReplyTo('username.name@a-bc.fr', 'First Last');
    $mail->AddAddress('username.name@a-bc.fr', 'John Doe');
    $mail->SetFrom('username.name@a-bc.fr', 'First Last');
    $mail->AddReplyTo('username.name@a-bc.fr', 'First Last');
    $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
    $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
    $mail->MsgHTML(file_get_contents('contents.html'));
    $mail->Send();

    echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
    echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
    echo $e->getMessage(); //Boring error messages from anything else!
}

【问题讨论】:

  • 您是否仔细检查了您的垃圾邮件文件夹?
  • 是的,但我没有找到任何邮件

标签: php smtp phpmailer


【解决方案1】:

除非您将true 传递给构造函数,否则PHPMailer 不会抛出异常,例如$mail = new PHPmailer(true);,因此您的代码不会导致任何异常被捕获,也不会报告任何错误。我建议您设置$mail-&gt;SMTPDebug = 3; 以获得更多关于该问题的反馈。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-10
    • 2015-06-04
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2011-04-06
    • 2017-10-05
    • 1970-01-01
    相关资源
    最近更新 更多