Jump to content

Mail Headers In Php Mail()


Russ
 Share

Recommended Posts

I have a question about setting email headers when using mail() in a php script.

 

When I send an email from my domain thru TCH Webmail (using, for example, xxx@MyDomain.net) to another email address (either on my domain or otherwise), the "Received:" header reads, in part, as follows:

 

Received: from localhost ([127.0.0.1] helo=www.MyDomain.net)

by habs.tchmachines.com with esmtpa (Exim 4.69)

(envelope-from <xxx@MyDomain.net>)

id 1NC2kc-00074p-9w

 

However, when I send an email using the script, I set the "From:" and "Return-path" to an email address I have for my domain (YYY@MyDomain.net). When I look at the header in the email that was received by the address to which the script sends the email, the "Received:" header has my CPanel user name in it - and that kind of makes me nervous. In particular, ere is what the "Received:" header looks like:

 

Received: from cPanelUserName by habs.tchmachines.com with local (Exim 4.69)

(envelope-from YYY@MyDomain.net)

id 1NC2J7-0006dF-7M; Sat, 21 Nov 2009 21:36:09 -0500

 

I have tried to modidfy the "Received:" header by changing adding some text to the header via the mail() function, but it doesn't change the "Received:" header.

 

Here is the code snippet I am using to send email and set headers:

 

>
//Some additional email headers

$add_headers = 'From: YYY@MyDomain.net' . "\r\n". "Return-path: YYY@MyDomain.net" . "\r\n";

mail('XXX@MyDomain.net', $subject , $message , $add_headers, "-f YYY@MyDomain.net");

 

I have tried to add additional header to the $Header variable to set the "Received:" header, but it doesn't change anything in the header of the received email.

 

I don't want to make the header fraudulent, but I would prefer not to disclose my cPanel username. I tried researching this on the Internet, but have not found anything helpful.

 

I checked with the TCH Help Desk, but they said that it was a not a server issue, but a scripting issue. They suggested I try to forum for assistance.

 

Any suggestions?

Edited by Russ
Link to comment
Share on other sites

>mail('XXX@MyDomain.net', $subject , $message , $add_headers, "-f YYY@MyDomain.net");

 

Try removing the space after the -f switch.

 

>mail('XXX@MyDomain.net', $subject , $message , $add_headers, "-fYYY@MyDomain.net");

 

Tried that, but it had no effect on the "Received:" header, which still reads:

 

Received: from cPanelUserName by habs.tchmachines.com with local (Exim 4.69)

(envelope-from YYY@MyDomain.net)

id 1NC2J7-0006dF-7M; Sat, 21 Nov 2009 21:36:09 -0500

Link to comment
Share on other sites

  • 2 weeks later...

The only solution is the one you have been given. I use the -femail@address.com in my mail sending and this is my header

 

>Received: from nobody by matra.tchmachines.com with local (Exim 4.69)
(envelope-from <noreply@carbonize.co.uk>)
id 1NFswf-00040K-CZ
for webmaster@carbonize.co.uk; Wed, 02 Dec 2009 12:24:53 -0500

 

So you need to check your code again or if you wish feel free to email me a copy to look at.

Edited by carbonize
Link to comment
Share on other sites

The only solution is the one you have been given. I use the -femail@address.com in my mail sending and this is my header

 

>Received: from nobody by matra.tchmachines.com with local (Exim 4.69)
(envelope-from <noreply@carbonize.co.uk>)
id 1NFswf-00040K-CZ
for webmaster@carbonize.co.uk; Wed, 02 Dec 2009 12:24:53 -0500

 

So you need to check your code again or if you wish feel free to email me a copy to look at.

 

 

Thanks, for your reply.

 

Here is the code snippet that I am using.

 

>
$add_headers = 'From: YYY@MyDomain.net' . "\r\n" . 'Return-path: YYY@MyDomain.net' . "\r\n";

mail('XXX@MyDomain.net', $subject , $message , $add_headers, "-fYYY@MyDomain.net");

 

This the "Received:" header in the recipient email:

 

Received: from cPanel_username by habs.tchmachines.com with local (Exim 4.69)

(envelope-from <YYY@MyDomain.net>)

id 1NFzWd-0006G0-Kf; Wed, 02 Dec 2009 19:26:27 -0500

 

 

It still has my cPanel username, rather than "Nobody." :clapping:

Link to comment
Share on other sites

I just tested using this bit of code

 

>$add_headers = 'From: YYY@MyDomain.net' . "\r\n" . 'Return-path: YYY@MyDomain.net' . "\r\n";

mail('webmaster@carbonize.co.uk', 'test' , 'Just a test message' , $add_headers, "-fYYY@MyDomain.net");

 

 

and here is the header

 

>Received: from nobody by matra.tchmachines.com with local (Exim 4.69)
(envelope-from <YYY@MyDomain.net>)
id 1NG6ly-0001se-39
for webmaster@carbonize.co.uk; Thu, 03 Dec 2009 03:10:46 -0500

 

Wonder if there is a problem with the sendmail on the habs server or if it is running in safe mode for some reason.

 

 

BTW this bit of code

 

$add_headers = 'From: YYY@MyDomain.net' . "\r\n" . 'Return-path: YYY@MyDomain.net' . "\r\n";

 

would be better as

 

$add_headers = "From: YYY@MyDomain.net\nReturn-path: YYY@MyDomain.net\n";

Link to comment
Share on other sites

Wonder if there is a problem with the sendmail on the habs server or if it is running in safe mode for some reason.

 

I had submitted a Help Desk ticket, but their response was as follows:

 

We are sorry that this Help Desk is primarily for server related issues and not much support for scripting level issues. Please refer to our user forums to have these kind of questions answered. There are many users that regularly visit the forums and are happy to share example code, discuss scripts they have used, and provide help for getting scripts up and running.

 

I assume that you are on a shared server?

 

At any rate, not sure what to do?

 

 

BTW this bit of code

 

$add_headers = 'From: YYY@MyDomain.net' . "\r\n" . 'Return-path: YYY@MyDomain.net' . "\r\n";

 

would be better as

 

$add_headers = "From: YYY@MyDomain.net\nReturn-path: YYY@MyDomain.net\n";

 

I am a newbie trying to pick up php, can you explain why your suggested code is better?

 

I really do appreciate you taking the time to help me with this.

 

Thank you.

Link to comment
Share on other sites

While I don´t know what you wrote in the help desk ticket, I would reopen the ticket and ask them specifically about the sendmail and the safe mode as Carbonize suggests.

 

As for for script support with the help desk, they are correct, script problems goes here, but they should be able to tell you about the sendmail and safe mode.

Link to comment
Share on other sites

While I don´t know what you wrote in the help desk ticket, I would reopen the ticket and ask them specifically about the sendmail and the safe mode as Carbonize suggests.

 

Thank you, Thomas, Carbonize and Bruce. I have reopened my Help Desk ticket. I will let you know how that goes.

Link to comment
Share on other sites

Russ,

 

There is no issues with sendmail and safe mode is not turned on. I am sorry, this was not clearly addressed on the tickets by us.

 

I ve gone through the same steps as carbonize did and here is the header

 

>
from nobody by habs.tchmachines.com with local (Exim 4.69)	(envelope-from <rph@********.net>)	
id 1NGBlk-0000s9-CG	
for alex@totalchoicehosting.com;

Link to comment
Share on other sites

Russ,

 

There is no issues with sendmail and safe mode is not turned on. I am sorry, this was not clearly addressed on the tickets by us.

 

I ve gone through the same steps as carbonize did and here is the header

 

>
from nobody by habs.tchmachines.com with local (Exim 4.69)	(envelope-from <rph@********.net>)	
id 1NGBlk-0000s9-CG	
for alex@totalchoicehosting.com;

 

First, thanks to all for the help.

 

Alex, I found your script and inserted my email address (in lieu of yours) and ran the script. The email that I received had a "Received:" header that was similar to the one you and carbonize received:

 

Received: from nobody by habs.tchmachines.com with local (Exim 4.69)

(envelope-from <XXX@MyDomain.net>)

id 1NGXu6-0005iK-SV

for XXX@MyDomain.net; Fri, 04 Dec 2009 08:08:58 -0500

 

 

I then cut and pasted the code from your script into the script that was set up with the pipe. When the pipe script sent the email, however, the "Received:" header had my cPanel username in it:

 

Received: from cPanel_username by habs.tchmachines.com with local (Exim 4.69)

(envelope-from <XXX@MyDomain.net>)

id 1NGXsg-0004x8-WF

for XXX@MyDomain.net; Fri, 04 Dec 2009 08:07:31 -0500

 

Isn't that weird?

Link to comment
Share on other sites

Isn't that weird?

 

I just had a thought....Maybe this could be the reason - When the email is sent with the script Alex created, it is sent by pointing the browser at the script. When the email is sent from the pipe script, it is a shell script. Could that difference account for the different "Received:" headers?

Link to comment
Share on other sites

  • 2 weeks later...

Sorry I haven't replied sooner - thought that I had "Reply Notification" sent, but it turns out that I didn't...

 

The help desk has made it clear that they "have limited" support for scripts and cannot help with this issue. So I don't see them helping on this topic any further.

 

As far as the "pipe script" is concerned, it is a php script that I wrote which reads an email that is "piped" to it and then the script sends an email. In cPanel, you set an "email forwarding" to the script (using "pipe"). Emails sent by that script will disclose my cPanel username in the "Received:" header; whereas, emails sent via a php script to which I point my browser (with identical "mail()" code) will result in a "Receved:"header similar to the one you generate.

 

Anyway thank for your help.

Edited by Russ
Link to comment
Share on other sites

It will be different from a piped script compared with a direct php because of the owner of the running process. When it is run from a web page it will be run as "nobody". When it is run from your piped script it will be running as your cpanel ID.

 

Thanks, Andy. Is there anyway to change that? Makes me nervous to send an email that would disclose my cPanel username.

Link to comment
Share on other sites

There isn't I'm afraid, as it's defined by the owner of the process that can't be changed. The only way I can think to get round it is to get the piped script to dump the data to a file, then to call the URL of a web page php to execute and send the email. That way it is a web page ( hence "nobody") sending the email.

Link to comment
Share on other sites

There isn't I'm afraid, as it's defined by the owner of the process that can't be changed. The only way I can think to get round it is to get the piped script to dump the data to a file, then to call the URL of a web page php to execute and send the email. That way it is a web page ( hence "nobody") sending the email.

 

Thank you, Andy. I will give that a try. I appreciate your help.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...