php mail() and Google apps or ...???

So I really just want to be able to send out a registration e-mail.

I'm still learning but is there someway I can set up google apps to be able to work with the php mail() function or do I need to install something like postfix?

9 Replies

Easier to just setup something like this

http://msmtp.sourceforge.net/

so that it relays it to Google App's for delivery.

You can also install postfix if you like (handy for receiving emails from the server not from php), you can also PHP's pear module Mail.

I personally use postfix with Mail pear module as a fallback.

I use SwiftMailer. It can talk to any SMTP server directly, including Google. It doesn't require Postfix to be installed locally when used in this fashion, so there's one less daemon to worry about. It's also a lot more powerful than mail() once you get used to the simple API. You can send multipart messages with embedded attachments and fancy stuff like that. Another option would be PHPMailer.

I just wrote a guide on setting up php mail() to work with msmtp and google apps here. Let me know if it works for you, as I might've left something out. It should work though.

Nissy,

Thanks for your guide! I haven't tried yet but I should be setting up my mail this week so will definitely let you know how it goes!

Nisstyre56,

I went through your steps and worked well for me, just a couple of minor points:

tlstrustfile /usr/share/ca-certificates/mozilla/ThawtePremiumServer_CA.crt should now be

EquifaxSecureCA.crt

Also (for other n00bs who also tend to copy and paste code) "sudo chown http /etc/msmtprc" should be "sudo chown www-data /etc/msmtprc" if you've done the default Linode install of Apache.

Thanks though, I've set it up now and works well (except for a problem I was having anyway, which hasn't gone away)

Glad it worked for you, and yeah, the user would be different depending on your distro. As for your other problem I can't really help considering I don't use Postfix, and that is most likely where the issue is.

Thanks so much for the msmtp guide! Worked perfectly. Just one question though. Is there a way to change the email address it is coming from? Or is this all handled on the gmail side? No matter what address I put in for the from line it comes from my gmail account thats authenticated. This would be fine except I have multiple domains and do not want the mail coming from x.com when y.com is the website thats being used?!? Any help is greatly appreciated.

@chrisg:

Thanks so much for the msmtp guide! Worked perfectly. Just one question though. Is there a way to change the email address it is coming from? Or is this all handled on the gmail side? No matter what address I put in for the from line it comes from my gmail account thats authenticated. This would be fine except I have multiple domains and do not want the mail coming from x.com when y.com is the website thats being used?!? Any help is greatly appreciated.
Yes, you should be able to do that, but it's a little extra work, since in my experience, the authenticated GMail account has to have been set up with the desired address(es) as an valid alternate address (which is thus verified as belonging to the same person). Otherwise it'll override the From header with the authenticated account. Essentially you're limited to controlling the From: field via the SMTP gateway to the same set of values you can use through the web interface.

So first sign onto the primary GMail account you are authenticating against. Then set up your desired addresses to use as alternate From values in the Settings/Accounts tab (in the "Send Mail As" section). Follow confirmation instructions as usual, which requires being able to receive mail to those accounts, so if you're sending on behalf of someone else you can enlist their help in forwarding over the confirmation message. Then you should be set.

You can't stop Gmail from placing your authenticated address in the Sender: field (which is reasonable, IMO) so if a receiving MUA erroneously decides to show that instead of the From: header you're stuck, but that would be non-compliant behavior on the part of the MUA. Again, no different from choosing a different From: address when sending a message from the web interface.

Note that any from value you give directly to msmtp is just going to get used for the envelope (the SMTP transaction), which aside from potentially showing up in a Received: header is not going to do much for how the mail is seen by people receiving it. You'll want to make sure that your desired address is placed in the From: header in the contents of the message being sent.

For example, in the referenced guide, when doing the test message include the line "From: " above the Subject: line and see if that works. Then just arrange for whatever in your application stack composes the contents of the message to include the proper From header.

– David

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct