wayne Posted December 14, 2005 Share Posted December 14, 2005 I have been told by the help desk that my php script which sends out an email receipt is no longer allowed on my server. It was a basic command in the form to mail($recipient,$subject,$body,$from) The reason is that it is sending out mail as nobody which is no longer allowed. I have many many php pages that use this script to send out receipts to customers. Is there a way to use php to send mail and not have it send it a "nobody". I do put a reply address in the $from variable but obviously that is not what is needed. Thanks in advanced. Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted December 14, 2005 Share Posted December 14, 2005 Use the -f switch to tell sendmail to set the envelope address: -f email@address.com Quote Link to comment Share on other sites More sharing options...
wayne Posted December 14, 2005 Author Share Posted December 14, 2005 Thanks I have found this reference to the -f switch <?php mail('nobody@example.com', 'the subject', 'the message', null, '-fwebmaster@example.com'); ?> Not sure what the null is. Do I leave this as null? What I want is an email sent out to my customer and to bcc myself. Would this work? <?php mail('customer@example.com', '$subject', '$message', null, '-fmyaddress@****'); ?> Not sure how I would get this to bcc me as well or can I do this? Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted December 14, 2005 Share Posted December 14, 2005 >mail($contactemail, $subject, $message, $headers, "-f".$myemail); Quote Link to comment Share on other sites More sharing options...
TCH-Andy Posted December 14, 2005 Share Posted December 14, 2005 Hi Wayne, The null that you have should really be the headers; Try; >$fromname = "me"; $fromemail = "me@here.com"; $toname = "you"; $toemail = "you@there.com"; $subject = "subject of email"; $message = "Test message\n"; $message .= "\n"; $message .= "signed\n"; $headers = "From: $fromname <$fromemail>\r\n"; $headers .= "Reply-To: $fromname <$fromemail>\r\n"; $headers .= "To: $toname <$toemail>\r\n"; $headers .= "bcc: $fromname <$fromemail>\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "X-Priority: 1\r\n"; $headers .= "X-MSMail-Priority: High\r\n"; $headers .= "X-Mailer: My script Mailer\n"; mail($toemail, $subject, $message, $headers, "-f".$fromemail); You do need to check that any variables you use that allow people to enter values into (ie, from a web page) are checked to ensure they only contain a single email address though - otherwise it quickly becomes very insecure. Quote Link to comment Share on other sites More sharing options...
wayne Posted December 14, 2005 Author Share Posted December 14, 2005 Thanks for the speedy responses. I will edit my scripts and yes I check the email addresses. Wayne Quote Link to comment Share on other sites More sharing options...
wayne Posted December 15, 2005 Author Share Posted December 15, 2005 I am having 2 problems. One of which I have fixed. This is what I have" $fromname = "wayne"; $fromemail = "wayne@here.com"; $toname = "customer"; $toemail = "customer@there.com"; $subject = "subject of email"; $message = "Test message\n"; $message .= "\n"; $message .= "signed\n"; $headers = "From: $fromname <$fromemail>\r\n"; $headers .= "Reply-To: $fromname <$fromemail>\r\n"; $headers .= "To: $toname <$toemail>\r\n"; $headers .= "bcc: $fromname <$fromemail>\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "X-Priority: 1\r\n"; $headers .= "X-MSMail-Priority: High\r\n"; $headers .= "X-Mailer: My script Mailer\n"; mail($toemail, $subject, $message, $headers, "-f".$fromemail); I have noticed 2 problems when I run the script as instructed above. The $toemail address is getting 2 emails. So I removed the $headers entry for the "To" field and now it is fixed (since the $toemail is also in the actual mail() command). HOWEVER I get the mail to $toname bouncing back. This email address is working as it is on my day job email address (on a server not located at TCH if that means anything). I do get the mail at the bcc address (which is an acount on the TCH server running the script). The error in the bounced mail is unrouteable mail domain "there.com" Any help is much appreciated. Wayne Quote Link to comment Share on other sites More sharing options...
TCH-Andy Posted December 15, 2005 Share Posted December 15, 2005 without the real domain name it's difficult to investigate. Although we don't provide coding support via the help desk, open a ticket and we'll take a quick look at why it's failing to that domain. Quote Link to comment Share on other sites More sharing options...
wayne Posted December 15, 2005 Author Share Posted December 15, 2005 actually it is any domain that is outside my server. ie I have tried hotmail.com, yahoo.ca and all fail Seems that if I make the address my own domain, I get the mail fine. Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted December 15, 2005 Share Posted December 15, 2005 I have no idea why you are getting errors Wayne. I copied and pasted your script into a test PHP file changed the email addresses to my own and it worked perfectly. Quote Link to comment Share on other sites More sharing options...
wayne Posted December 15, 2005 Author Share Posted December 15, 2005 Bruce I opened a help desk ticket and they fixed something on the server end. All is now working with the -f switch. Thanks all for your advice, as usual service here at TCH ROCKS!! Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted December 15, 2005 Share Posted December 15, 2005 Glad it's working. Quote Link to comment Share on other sites More sharing options...
TCH-Rob Posted December 15, 2005 Share Posted December 15, 2005 Alright Wayne, nice to see you are on the road again. 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.