简体   繁体   中英

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!

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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