Phpmailer: setFrom didn't work as expected

Created on 27 Oct 2017  路  1Comment  路  Source: PHPMailer/PHPMailer

Please check these things before submitting your issue:

  • [x ] Make sure you're using the latest version of PHPMailer
  • [x ] Check that your problem is not dealt with in the troubleshooting guide, especially if you're having problems connecting to Gmail or GoDaddy
  • [x ] Include sufficient code to reproduce your problem
  • [ ] If you're having an SMTP issue, include the debug output generated with SMTPDebug = 2 set
  • [ ] If you have a question about how to use PHPMailer (rather than reporting a bug in it), tag a question on Stack Overflow with phpmailer, but search first!

Problem description

The expected working of function setFrom is set a header indicate the from field. But in the received mail, it shows the from address as the authenticated gmail address.

Code to reproduce

The example you've given in the readme

Pictorial Representation

image

Most helpful comment

This is expected behavior, there is nothing wrong in PHPMailer itself.

The rewriting of the From address is done by Gmail for security reason (fight SPAM, phishing, etc.), not by PHPMailer. Gmail (and many others) doesn't allow sending messages with random From addresses.

To fix your problem, do one of:

  • Use another From address than [email protected], a real address that you own. If this is not the same address than the Gmail account you connect with for sending the e-mail, also add that address in your Gmail account according to instructions on https://support.google.com/mail/answer/22370?hl=en
  • Find and use another SMTP server than Gmail, one that does not rewrite From addresses.

>All comments

This is expected behavior, there is nothing wrong in PHPMailer itself.

The rewriting of the From address is done by Gmail for security reason (fight SPAM, phishing, etc.), not by PHPMailer. Gmail (and many others) doesn't allow sending messages with random From addresses.

To fix your problem, do one of:

  • Use another From address than [email protected], a real address that you own. If this is not the same address than the Gmail account you connect with for sending the e-mail, also add that address in your Gmail account according to instructions on https://support.google.com/mail/answer/22370?hl=en
  • Find and use another SMTP server than Gmail, one that does not rewrite From addresses.
Was this page helpful?
0 / 5 - 0 ratings