Search code examples
phpsmtpphpmaileremail-headersenvelope

phpmailer complications for spam filters "-f"


My clients hosting service isn't accepting emails sent from the website that doesn't have "-f" at the start of the FROM address. This related to a recent outgoing SPAM filter they added.

Official response is:

“senders envelope of data” is missing certain elements

I use phpmailer, everything was working fine until now using SMTP authentication.

But now with phpmailer, this DOESN'T work

$mail->From         = '[email protected]';

Also doesn't work

$mail->From         = '-f [email protected]';

Its invalid obviousdly, not a good looking email address.

I CAN get mail to actually send like this:

mail('[email protected]', 'the subject', 'the message', null, '-f [email protected]');

But that isn't phpmailer, this is the garden variety php function. So im trying to make PHPmailer add "-f " to the FROM automatically somehow.

Should I be adjusting the class files to somehow get around that? Stuck!


Solution

  • You've got your transports mixed up. -f in the mail() function is an additional parameter passed to the underlying sendmail binary that sets the envelope sender of the message (and officially it should not have a space after it, like [email protected]). However, it does not apply when you are sending via SMTP because you get control over that parameter with the Sender property. You should do this:

    $mail->Sender = '[email protected]';
    

    If you send using SMTP it will use that as the envelope sender (as the content of the SMTP MAIL FROM command), and if you send via isMail() or isSendmail() transports, it will set the sender via the -f property.

    Also make sure you're using the latest PHPMailer from GitHub.