Currently my situation is the following:

I am using Wordpress which handles a few things mail related: Registration forms that send a notification and contact form that send a message. However, because the mail server we use it a remote mail server connected to with SMTP, the contact form is confusing. The email that is received by the contact form should say it is from the person who fills the contact form out, but is instead forced to conform to the SMTP email settings and says it is from the SMTP email.

  1. Stranger 1 fills out contact form, providing Name, Email, and Message.
  2. Website sends form out, but because of SMTP, overrides the Sender's Name and Sender's email to the SMTP credentials.
  3. The final email recieved has the SMTP credentials, but the same message.

We want to use Google Apps Business and their mail servers, but according to the Gmail API (https://developers.google.com/gmail/api/ and https://cloud.google.com/appengine/docs/php/mail/#Sending_Mail) to connect to these mail servers, we'd have to use SMTP or IMAP.

We know we can create a dummy email for SMTP settings and have the website send using that configuartion, but we need another solution.

Is there a way into making Wordpress think that the Google mail servers are local mail servers so that phpmail can be used properly?

Is there an alternative solutions?

  • 2
    You can set the $headers[] = 'From: of the email, but this can and probably will break the sender domain policy (spoofing) and either be blocked by a host or end of being considered spam. This question doesn't really have anything to do with WP as it is.
    – Wyck
    Commented Nov 30, 2014 at 23:42
  • Right, google won't allow spoofing nor the webhost.
    – Busho
    Commented Dec 1, 2014 at 19:10

3 Answers 3


Is there a way into making Wordpress think that the Google mail servers are local mail servers so that phpmail can be used properly?

Yes, you could use a firewall to create a localhost:465 socket that forwards network traffic to smtp.gmail.com:465 but what on earth for??

Is there an alternative solutions?

Yes, and you're half way there with Google Apps.

Using Google's Domain Manager, create a mailbox group, like [email protected], and add everybody who should be able to read these emails to that group, such as [email protected] and [email protected]

Then in your contact form's settings:

When the receiver gets the email it has the customer name as the from, clear as day. When the receiver hits reply on this form, the email is automatically addressed to the customer who filled it out. Nothing confusing about it, and you avoid violating Gmail's sending restrictions.

Postman is an OAuth2 SMTP plugin specifically designed for sending mail with Google Apps. You WILL have problems sending Gmail with PHPMail because of the older authentication it uses, especially with Google Apps.

Is there a better way than SMTP?

Well there's the Gmail API but unless you're doing transactional email or all your SMTP ports are blocked, you don't need it.


Basically, your question is asking "how do I spoof the From header" and the answer is, essentially, that you don't.

While email in general has always been very non-secure in that spoofing a From is easy, over the years, lots of solutions have been devised to block emails which have an incorrect from. Those solutions are what is blocking you, and there's no way around them because they happen on the receiving end.

So, you can send the email with any From you like. The code to do so is rather trivial. But the email server that receives the result will be performing a check and then rejecting your email, or marking it as spam, or whatever else that particular email provider does.

You can't work around that. You only can control what you send, not what the receiving party does with it. So the long and the short of it is that while you can set the From to whatever you want, that's "spoofing" and it will probably be blocked in some manner.

Best advice: Tell your client to get over it. Sorry. You can't send email from another person without actually being that other person and using their servers to send the email how they would normally send email. Not 100% of the time, anyway. Not reliably.


I don't know which contact form and mailing plugins you are using, but in general you shouldn't configure contact form mails to be coming from the email address entered. Many E-Mail servers don't accept mail like this.

Instead you should properly configure a Reply-To: header with the info entered in the form. If this is done correctly, the recipient of the contact form mail can simply click on relpy in his Mail client / Webmail and will reply to the info entered in the contact form.

The info for the From: header should provide an existing E-Mail address which is authenticated with the credentials you use to connect to the Google SMTP servers.

As wordpress doesn't have a contact form itself, you are probably using a plugin. As you haven't supplied any info about which plugin is in use, I can't provide an exact info on how to configure it.

  • The reply-to is properly working, it just bothers the client that the email itself is coming from not that person.
    – Busho
    Commented Dec 1, 2014 at 19:11
  • What about adding the name entered in the contact form like this: From: Name_from_form<[email protected]>? This will at least show the Name in the from field and google shouln't care about the name as long the email underneath is what google expects.
    – JHoffmann
    Commented Dec 1, 2014 at 19:43
  • The dummy email approach is something we are considering. Ideally though, we want the name to be of that person, but dynamically spoofing that is not allowed.
    – Busho
    Commented Dec 1, 2014 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.