PHP sendmail_path with multiple accounts.

I configured my server to send SMTP (Gmail) via PHP using this tutorial.

“For Gmail, use the following settings: account gmail tls on tls_certcheck off auth on host port 587 user from password yourgmailPassw0rd This file can also have more than one account, just ensure that the “account” value is unique for each section. Save the file and use chmod to make this file readable only by the owner since it contains passwords. This step is mandatory because msmtp won’t run if the permissions are more than 600.”

It says this file can have more than one account so I have SMTP connections for 2 websites in the file. Both have a unique name and are configured to send with a custom from address (Gmail is able to send mail as these addresses, both have been tested). My problem is the server has one php.ini file where sendmail_path has a -a ACCOUNT1 flag. How can I configure sendmail_path to send from whichever account in my MSMTPRC file the from address belongs to?

Thank you for any advice.

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
March 6, 2022

Hi @brianScubadiver,

To be honest, I’ve never had to find such a solution so far, what you found however is a really good solution, thank you for sharing it with the community!

I found a solution that seems to be working correctly. My master php.ini sendmail_path has the MSMTP account for my main website. In the apache virtual host files (I had one for HTTP and one for HTTPS) for my second website I added this…

<Directory /var/www/> php_admin_value sendmail_path “Custom path for this domain only” </Directory>

I am now receiving mail from the correct account and seeing the message in my google workspace sent items under the correct user.