Tutorial :PHP mail function does not send email to valid account on same domain


I'm using the mail function as follows:

mail($emailto, $subject, $body, $headers);  mail('askme@mysite.com', $subject.' / '.$emailto, $body, $headers);  

The first is intended for the enduser. The second copy is for me for record keeping purposes.

Soometimes the enduser specifies their email address, other times its blank.

  1. When an email address is specified, the end user actuallys gets the email without any problem
  2. However, no email gets sent to askme@example.com in EITHER case - I've checked the spam folders as well.

In my /mail/new folder I see many FILES created similar to the below. The error is incorrect as askme@mysite.com is a VALID email address (setup using google for domains).

  Return-path: <>    Envelope-to: myuserid@myhostingprovider.com    Delivery-date: Mon, 28 Jun 2010 12:37:28 -0400    Received: from mailnull by myhostingprovider.com with local (Exim 4.69)        id UNIQUEIDZ-7x        for myuserid@myhostingprovider.com; Mon, 28 Jun 2010 12:37:28 -0400    X-Failed-Recipients: askme@mysite.com    Auto-Submitted: auto-replied    From: Mail Delivery System <Mailer-Daemon@myhostingprovider.com>    To: myuserid@myhostingprovider.com    Subject: Mail delivery failed: returning message to sender    Message-Id: <EUNIQUEIDZ-7x@myhostingprovider.com>    Date: Mon, 28 Jun 2010 12:37:28 -0400      This message was created automatically by mail delivery software.      A message that you sent could not be delivered to one or more of its    recipients. This is a permanent error. The following address(es) failed:        askme@mysite.com        No Such User Here      ------ This is a copy of the message, including all the headers. ------      Return-path: <myuserid@myhostingprovider.com>    Received: from nobody by myhostingprovider.com with local (Exim 4.69)        (envelope-from <myuserid@myhostingprovider.com>)        id UNIQUEIDV-6b        for askme@mysite.com; Mon, 28 Jun 2010 12:37:28 -0400    To: askme@mysite.com    Subject: mysite.com: SUBJECT / enduser@gmail.com    X-PHP-Script: www.mysite.com/mysitescript.php for IPADDRESS    MIME-Version: 1.0    Content-type: text/html; charset=UTF-8    From: mysite.com Service <askme@mysite.com>    Message-Id: <EUNIQUEIDV-6b@myhostingprovider.com>    Date: Mon, 28 Jun 2010 12:37:28 -0400  


Two things:

  1. You should check to see if $emailto is blank before actually calling the mail function. You don't want PHP to try to send mail to a blank address.

  2. Your problem with askme@mysite.com not being delivered is probably a result of your local website host (mysite.com) trying to deliver mail to what it considers a "local" address - since it's on the same domain, when in reality that email exists out in Google Apps. Your mail server (like postfix or sendmail) should have a setting to disable this "shortcut".


Can you send an email to that address using a normal email client (web one like hotmail/gmail or Outlook/Thunderbird)?

If you can't - your email account isn't setup correctly.

If you can - your email account is setup to ignore your domain or something similar (perhaps a spamfilter pretending the user does not exist?).


If you are using sendmail go to the config file and using MX records to point to Google Apps like I do, do the following:

sudo vim /etc/mail/sendmail.mc  

add this:


restart send mail

sudo /etc/init.d/sendmail restart  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »