Home > Software engineering >  PHPMailer | (mail from) Sender not allowed
PHPMailer | (mail from) Sender not allowed

Time:10-14

I have a contact form made using PHPMailer. It has been working since today, then it suddenly stopped working. I tried to understand why and I discovered I get everytime error about the sender which is not allowed as it says. Here is the code:

try {

  $mail->SMTPDebug = 2;
  $mail->isSMTP();
  $mail->Host = 'smtps.aruba.it';
  $mail->SMTPAuth = true; 
  $mail->Username = '[email protected]'; 
  $mail->Password = 'myPassword';
  $mail->SMTPSecure = 'tls'; 
  $mail->Port = 587;
  
  $mail->setFrom("[email protected]", 'Sender'); // Here is where I put the sender email

  $mail->addAddress('[email protected]');
  $mail->isHTML(true); 
  $mail->Subject = "Subject";  
  $mail->Body    = "Body";

  if (!$mail->send()) { 
    $result = array('status'=>"error", 'message'=>"Mailer Error: ".$mail->ErrorInfo);//
    print_r(json_encode($result));

  } else {
    $result = array('status'=>"success", 'message'=>"Message sent.");
    print_r(json_encode($result));

  }
}

catch (Exception $e) {
    echo "Error excpetion: ".$e;
}

Here is the error I get from the debug:

The following From address failed: [email protected]: MAIL FROM command failed,<[email protected]> ik2dozQHmuz2mik2doPsAn - Mittente non consentito / Sender not allowed ( mail from )

I tried to update PHPMailer, now I have the latest version. Also, I tried with an outlook.it email I have, but same error again. It was perfectly working since today, can you help me?

CodePudding user response:

Most likely the server admin has applied anti email spoofing policy today, so yesterday it works, but today it disallows you to send thru smtps.aruba.it as sender '[email protected]'

The proper way is to change your "from" address to [email protected], but if you want the recipient to reply your email but get it sent to [email protected], then add the following

$mail->ClearReplyTos();
$mail->addReplyTo('[email protected]', 'your name in gmail');

Alternatively, use gmail smtp server to send out the email thru PHPMailer (you may refer to the official link: https://support.google.com/a/answer/176600?hl=en for the smtp settings needed)

In case you have other problems in using gmail smtp, you may also wish to refer to this SO post (or other related ones)

PHPMailer does not work with Gmail SMTP

  • Related