dousaoxiancy199896 2015-03-17 12:06
浏览 45

PHPmailer不工作的收件人

I have a problem, with my code beneath I get this error message: Message could not be sent.Mailer Error: SMTP Error: The following recipients failed: !Censored!

I have looked into the Host, Port, Username, Password, Recipient and all is correct, what is the problem? Thank you!

Could you please explain too cuz Im new to PHP-coding

 <?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['amne'];
$message = $_POST['message'];

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = '!Censored!';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '!Censored!';                 // SMTP username
$mail->Password = '!Censored!';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = $email;
$mail->FromName = $name;
$mail->addAddress('!Censored!');     // Add a recipient

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = $subject;
$mail->Body    = $message;
$mail->AltBody = $message;

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

EDIT: I found the problem, the problem was not in the php code itself. It was in the contact form. The problem started when I put the variables as names and emails. If the email is not verified, it does not work.

  • 写回答

1条回答 默认 最新

  • douchuang8359 2015-03-17 12:53
    关注

    This error can be caused by a few different things. You can get a better idea of the reason by adding the following line to your PHPMailer script:

    $mail->SMTPDebug = 2; //<-- For debugging
    

    Once you do that, you can check the following things that may be causing the error:

    1.) A corrupt class.phpmailer.php file.

    2.) The error may be caused by protection put in place by your ISP. Check with them.

    3.) It could be a problem with the recipient's/sender's email addresses.

    4.) Set SMTPAuth to true for PHPMailer class.

    5.) Comment out the following line in your PHPMailer script: $mail->isSMTP();

    Mostly, There is possibility that Your phpmailer class file is corrupted.

    Download the latest version: https://github.com/PHPMailer/PHPMailer

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP