Russ Posted November 22, 2009 Share Posted November 22, 2009 (edited) 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 November 22, 2009 by Russ Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted November 22, 2009 Share Posted November 22, 2009 >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"); Quote Link to comment Share on other sites More sharing options...
Russ Posted November 22, 2009 Author Share Posted November 22, 2009 >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 Quote Link to comment Share on other sites More sharing options...
Russ Posted December 2, 2009 Author Share Posted December 2, 2009 Nobody has any other thoughts on resolving this? Quote Link to comment Share on other sites More sharing options...
carbonize Posted December 2, 2009 Share Posted December 2, 2009 (edited) 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 December 2, 2009 by carbonize Quote Link to comment Share on other sites More sharing options...
Russ Posted December 3, 2009 Author Share Posted December 3, 2009 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." Quote Link to comment Share on other sites More sharing options...
carbonize Posted December 3, 2009 Share Posted December 3, 2009 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"; Quote Link to comment Share on other sites More sharing options...
Russ Posted December 3, 2009 Author Share Posted December 3, 2009 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. Quote Link to comment Share on other sites More sharing options...
TCH-Thomas Posted December 3, 2009 Share Posted December 3, 2009 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. Quote Link to comment Share on other sites More sharing options...
Russ Posted December 3, 2009 Author Share Posted December 3, 2009 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. Quote Link to comment Share on other sites More sharing options...
TCH-Alex Posted December 3, 2009 Share Posted December 3, 2009 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; Quote Link to comment Share on other sites More sharing options...
Russ Posted December 4, 2009 Author Share Posted December 4, 2009 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? Quote Link to comment Share on other sites More sharing options...
Russ Posted December 4, 2009 Author Share Posted December 4, 2009 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? Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted December 4, 2009 Share Posted December 4, 2009 It should make no difference. Quote Link to comment Share on other sites More sharing options...
Russ Posted December 4, 2009 Author Share Posted December 4, 2009 It should make no difference. Okay. Well, then again, that's weird. With what amounts to the same code, two diffenent scripts are generating two different "Received:" headers? Quote Link to comment Share on other sites More sharing options...
carbonize Posted December 10, 2009 Share Posted December 10, 2009 (edited) Given you have now narrowed it down to emails being sent from the pipe script you could pass this information on in a ticket. Although I'm confused as to what you mean by a pipe script. Edited December 10, 2009 by carbonize Quote Link to comment Share on other sites More sharing options...
Russ Posted December 18, 2009 Author Share Posted December 18, 2009 (edited) 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 December 18, 2009 by Russ Quote Link to comment Share on other sites More sharing options...
TCH-Andy Posted December 19, 2009 Share Posted December 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
Russ Posted December 19, 2009 Author Share Posted December 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
TCH-Andy Posted December 19, 2009 Share Posted December 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
Russ Posted December 22, 2009 Author Share Posted December 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.