homepage Welcome to WebmasterWorld Guest from 54.166.66.204
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP sendmail from a subdomain
remote host cannot verify my server
adder




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

Hi,

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:

<?php
$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!";
}
?>

 

swa66




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

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.

adder




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved