简体   繁体   中英

PHP mail is not sending from mydomain.com to the google apps email myname@mydomain.com

When i am trying to send a mail from a contact form in my website using the
PHP mail function its not sending from mydomain.com to the google apps email myname@mydomain.com.

Please suggest a solution for the issue.

After a very long research, I found the answer to this problem.

For me, the problem is in my host settings.

You host treats those domain addresses as they were registered with itself not with Google Apps. So it routes the emails to hosts mail server.

To route it through Google Apps (Gmail), you need to change the email routing settings.

Find "MX Entry" settings in your cpanel and add a new MX Record with priority

0

and destination

gmail.com

and add it. You should also change the existing MX Record priority to 1.

These settings will let your receive emails from php mail() to your Google Apps gmail account.

To send email from PHP you must have an SMTP server installed and have PHP configured to use the server. If you are using shared hosting or have it set up, you should check that you are calling the mail function correctly by checking the documentation .

Here is an example of how it is used:

$to = "name@example.com";
$subject = "Test Message";
$message = "Hello!";
$headers = "From: me@example.org";

mail($to, $subject, $message, $headers);

Just modify the /etc/hosts file and add your IP Address mydomain.com mydomain in the next line, this should work by routing emails to google's servers .I did the same for my site.

So my /etc/hosts file looks like this :

127.0.0.1 localhost IP mysite.com mysite (this is an alias and you can call it anything i suppose)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM