This article shows you how to fix issues where recipients of email that is generated from PHP scripts are seeing "via primary-domain.com" in the From field. This is caused by a mismatch of the envelope-from (listed in the email header) and From fields due to the use of an alternate domain to send mail. By default, the primary domain is the domain that you used to open your Media Temple hosting service. It's also possible to change your primary domain using the Account Center.
- For example, Gmail may add "via primary-domain.com" to the From field. This can be confusing to mail recipients and you may want to consider modifying your scripts to prevent this from occurring.
Important Note: This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by Media Temple. Please take a moment to review the Statement of Support.
- Access to your mailer scripts or WordPress dashboard
PHP's mail() and PHPMailer are very popular ways to send email from domains. You may be using one of these to generate email in a variety of ways. In order to fix the issue with the From field, we'll need to modify your script(s) to force the envelope-from field in the email header to match the alternate domain that the script is actually being generated from. This will prevent the From field of your message from saying via-primarydomain.com or similar.
Tip: If you don't want to alter your scripts, you may want to consider changing your primary domain to the domain that you're sending mail from.
Note: Modifying the send_mail path in your php.ini will not solve the issue due to the envelope-from field remaining the same.
Mail sent from mail():
Modify the mail() portion of your script with the -f option.
mail('firstname.lastname@example.org','subject!','body!','From: email@example.com','-f firstname.lastname@example.org');
Note that the last parameter passed to the PHP mail function is -f envelope-sender. This option will prevent the mismatch that causes the "via primary-domain.com" tag.
Mail sent from PHPmailer:
Set the envelope-sender using SetFrom.
$mail->SetFrom('email@example.com', 'Your name');
Mail sent from WordPress:
An easy way to fix issues with your WordPress mailer is to use the WP Mail SMTP plugin.
- From Wordpress.org: WP Mail SMTP "Reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page to manage the settings."
This plugin has easy to use options that allow you to set the From email and return path. Install the plugin using the WordPress dashboard and navigate to the settings page for WP Mail SMTP.
You should now be able to send email from your scripts without worrying if your recipients have a "via primary-domain.com" tag in the From field. As always, please feel free to contact Media Temple's award-winning 24/7 support with any additional questions or concerns.