PHPMailer .Exception:SendAsDeniedException.MapiExceptionSendAsDenied

前端 未结 4 683
南笙
南笙 2020-12-20 19:26

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:



        
4条回答
  •  孤城傲影
    2020-12-20 19:41

    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.

提交回复
热议问题