Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP sendmail from a subdomain

remote host cannot verify my server



3:34 pm on Jan 22, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month


I've got a weird server setup (long story) so when trying to use sendmail, it will send from root@server.mydomain.com instead of root@mydomain.com

Because of this peculiarity, the server cannot be verified by the remote host.

I'm almost 100% sure there was a workaround that could be applied to the script itself but I can't remember what it was. Can you please suggest?

This is the script I'm using:

$to = "email@example.com";
$subject = "Test Email";
$headers = "From: noreply@mydomain.com\r\n";
$headers .= "Reply-To: noreply@mydomain.com\r\n";
$headers .= "Return-Path: noreply@mydomain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = "<h1 style='font-family:Helvetica,Arial;font-size:16px'>Hi There</h1><p>This is a test!</p>";

if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";


5:01 pm on Jan 22, 2014 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

You have a MAIL FROM in the enveloppe of the email and you have a From: in the header.
They are unrelated and not linked.

The enveloppe is used by mail transfer agents (MTAs - such as sendmail) to communicate with other MTAs. The enveloppe is removed before it's delivered in a mailbox of a user.

Why are they different: not so much for the From, but for the To, and Cc: and even more importantly: the bcc: not all copies stay together (say you send a mail to a gmail and to a hotmail user: it'll get spilt up to go to MSFT and a copy to go to Google. But those servers can't use the header as that's still to specify all targets, yet they only need to cover their part.

With your code you're only specifying the code in the header of the email, not touching the one in the enveloppe (which will default typically to the unixuser@machinename,example.com that's normal and expected.

mail($to,$subject,$message,$headers,'-f from@example.com'); should do the trick.
Ref: [php.net...]

caveat: your sendmail needs to be configured to accept the -f option from the user that runs the php script (if running from the webserver that's the web server)
Typically that's configured in /etc/mail/trusted-users nowadays.


5:41 pm on Jan 22, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month

@swa66, wow, thank you for an impressive and detailed answer.
Problem fixed!

Featured Threads

Hot Threads This Week

Hot Threads This Month