PHPMailer .Exception:SendAsDeniedException.MapiExceptionSendAsDenied
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("[email protected]");
$mail->FromName = trim_input($_POST['Name']);
$mail->AddAddress("[email protected]", "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.