简体   繁体   English

PHPmailer无法正常工作的收件人

[英]PHPmailer not working recipient

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! 我有一个问题,我的代码在下面,我收到此错误消息:无法发送消息。Mailer错误:SMTP错误:以下收件人失败:!被检查!

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 您能否解释一下Cuz Im是PHP编码的新手?

 <?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. 编辑:我发现了问题,问题不在php代码本身。 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. 如果电子邮件未通过验证,则无法使用。

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: 通过将以下行添加到PHPMailer脚本中,可以更好地了解原因:

$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. 1.)损坏的class.phpmailer.php文件。

2.) The error may be caused by protection put in place by your ISP. 2.)错误可能是由您的ISP进行的保护所引起的。 Check with them. 与他们核对。

3.) It could be a problem with the recipient's/sender's email addresses. 3.)收件人/发件人的电子邮件地址可能有问题。

4.) Set SMTPAuth to true for PHPMailer class. 4.)将PHPMailer类的SMTPAuth设置为true。

5.) Comment out the following line in your PHPMailer script: $mail->isSMTP(); 5.)在PHPMailer脚本中注释掉以下行:$ mail-> isSMTP();

Mostly, There is possibility that Your phpmailer class file is corrupted. 通常,您的phpmailer类文件可能已损坏。

Download the latest version: https://github.com/PHPMailer/PHPMailer 下载最新版本: https : //github.com/PHPMailer/PHPMailer

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

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