I have installed PHPMailer on my website. But, I can\'t get it to work the way it should. When I send an email through the website, I get the following error:
I'd guess that the culprit is this:
$mail->FromName = trim_input($_POST['Name']);
What you're doing here is asking outlook to forge the from address by using arbitrary user input. This is generally a bad idea. The error message name suggests that this is where the problem is too: SendAsDeniedException
, i.e. it doesn't like who you're sending as.
Try this instead:
$mail->From = trim_input("receivingEmailAdress@outlook.com");
$mail->FromName = trim_input($_POST['Name']);
$mail->AddAddress("receivingEmailAdress@outlook.com", "my name");
$mail->AddReplyTo(trim_input($_POST['Email']), trim_input($_POST['Name']));
This is: put your own address as the from address (so you're not forging anything), and use the submitter's address as a reply to, and also use their name alongside the from address.
This problem is covered in the PHPMailer troubleshooting guide.
This error can also mean another thing as it did for me. So make sure also if the $mail->From
address is the same as the address you're using to authorize because otherwise you'll see this error:
554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;
Failed to process message due to a permanent exception with message Cannot submit message.
I solved by change
$mail->setFrom('test@hostinger-tutorials.com', 'Your Name');
To be the same $mail->Username
$mail->Username = 'example@hotmail.com';
to be like that :
$mail->setFrom('example@hotmail.com', 'Your Name');
Office 365 requires the "<" and ">" characters since September 1st, 2018.
This can often be fixed by updating the settings on the device or printer by adding angle brackets ("<" and ">") around the Reply or Mail From address.
See Microsoft's support for details.