uwptaik Posted April 11, 2007 Share Posted April 11, 2007 Greetings, I have setup a PHP script that sends emails from my account esteban@solabroad.com (pulled a simple MYSQL DB) it works perfectly. However, if the email is sent to an invalid email address, the message DOES NOT bounce correctly. Instead of the email being sent back to esteban@solabroad.com it is sent to Return-Path: <nobody@server115.tchmachines.com> I've been trying for three weeks now to fix this, so that emails bounce correctly. Everything I try has the same result. I have the PHP script header for the email set as $headers = "From: Esteban <esteban@solabroad.com>\r\n"; $headers .= "Reply-To: Esteban <esteban@solabroad.com>\r\n"; $headers .= "Return-Path: Esteban <esteban@solabroad.com>\r\n"; The email is received as with this header: From Esteban Wed Apr 11 09:19:43 2007 Return-Path: <nobody@server115.tchmachines.com> Authentication-Results: mta521.mail.mud.yahoo.com from=solabroad.com; domainkeys=neutral (no sig) Received: from 69.50.222.34 (EHLO server115.tchmachines.com) (69.50.222.34) by mta521.mail.mud.yahoo.com with SMTP; Wed, 11 Apr 2007 09:19:43 -0700 Received: from nobody by server115.tchmachines.com with local (Exim 4.63) (envelope-from <nobody@server115.tchmachines.com>) id 1HbfXr-0003aM-9g for estebanlardone@yahoo.com; Wed, 11 Apr 2007 09:19:43 -0700 To: estebanlardone@yahoo.com Subject: Hola Esteban! Study abroad this summer! From: Esteban <esteban@solabroad.com> Reply-To: Esteban <esteban@solabroad.com> Message-Id: <E1HbfXr-0003aM-9g@server115.tchmachines.com> Date: Wed, 11 Apr 2007 09:19:43 -0700 Content-Length: 929 Can somebody at TCH please help me with the correct header? Please help! Esteban esteban@solabroad.com Quote Link to comment Share on other sites More sharing options...
MikeJ Posted April 11, 2007 Share Posted April 11, 2007 The "From:" header is pretty much cosmetic, meaning it doesn't affect mail delivery just what the user sees. "Reply-To:" is only used by email clients when replying to the email. When you send mail, what gets set in SMTP as the "MAIL FROM:" line (which in this case is set to nobody@...) is what will be used for the bounce. How are you interfacing with the email system from your PHP script? If you are using PHP's mail() function, here's an example replacement that should allow you to specify the MAIL FROM to be your own address: http://www.zend.com/code/codex.php?id=72&single=1 Quote Link to comment Share on other sites More sharing options...
uwptaik Posted April 11, 2007 Author Share Posted April 11, 2007 Thank you Mike for your response! Yes, I'm using PHP's mail() function: mail ( "$cur_email", "Hola $first_name! Study abroad this summer!", $emailbodycontact, $headers); and the header: $headers = "From: Esteban <esteban@solabroad.com>\r\n"; $headers .= "Reply-To: Esteban <esteban@solabroad.com>\r\n"; $headers .= "Return-Path: Esteban <esteban@solabroad.com>\r\n"; Do you have another example where I can enter the "MAIL FROM:" into the header, I could not figure it out from the example you gave. thanks again Quote Link to comment Share on other sites More sharing options...
MikeJ Posted April 11, 2007 Share Posted April 11, 2007 mail ( "$cur_email", "Hola $first_name! Study abroad this summer!", $emailbodycontact, $headers); In the example, you would put that code within your script, and change the above mail line to: >mailfrom($fromaddress, "$cur_email", "Hola $first_name! Study abroad this summer!", $emailbodycontact, $headers); And define $fromaddress to be your email address, or just use "esteban@solabroad.com" (including quotes) in place of $fromaddress in that line. Quote Link to comment Share on other sites More sharing options...
uwptaik Posted April 11, 2007 Author Share Posted April 11, 2007 Mike! I tried that and got: Fatal error: Call to undefined function: mailfrom() in /home/uwptaik/public_html/testemailMass.php on line 74 is mailfrom a PHP command? Does it maybe have another name? thank you Quote Link to comment Share on other sites More sharing options...
MikeJ Posted April 11, 2007 Share Posted April 11, 2007 You would have to include that mailfrom() function in the link from my first post within your php page. It's not a standard php function, you would have to define it using that code before using it. Quote Link to comment Share on other sites More sharing options...
uwptaik Posted April 20, 2007 Author Share Posted April 20, 2007 Does anybody out there have a more simple way to address this? maybe a built in PHP function that will allow me to change the header? Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted April 20, 2007 Share Posted April 20, 2007 Just add "-fyour-email-address" to your current mail string. Quote Link to comment Share on other sites More sharing options...
uwptaik Posted April 20, 2007 Author Share Posted April 20, 2007 thanks! so that it looks like this? $headers = "From: Esteban <esteban@solabroad.com>\r"; $headers .= "Reply-To: Esteban <esteban@solabroad.com>\r"; $headers .= "Return-Path: Esteban <esteban@solabroad.com>\r"; $headers .= "-f<esteban@solabroad.com>\r"; Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted April 20, 2007 Share Posted April 20, 2007 No it's not part of your headers. It is for setting the return address on the mail command line. >mail("xxx@xxxxx.com","Test Email",$Message,$headers, "-fyour-email-address"); Quote Link to comment Share on other sites More sharing options...
carbonize Posted April 20, 2007 Share Posted April 20, 2007 I've been reading this thread with interest and am going to slap this bit of code into the next release of Lazarus. So just to confirm after all the other headers you just use -femail@address.com with no space ? Naturally with a new line between the previous header and the -f. Quote Link to comment Share on other sites More sharing options...
click Posted April 20, 2007 Share Posted April 20, 2007 (edited) No, the "-f email@address.com" (I believe there should be a space) is a command line switch used in the call to sendmail. When using php's mail() function, it's specified in the 5th parameter -- Bruce's post was missing the comma. Check out http://www.php.net/manual/en/function.mail.php. Edited April 20, 2007 by click Quote Link to comment Share on other sites More sharing options...
carbonize Posted April 20, 2007 Share Posted April 20, 2007 (edited) You're right that he missed out the comma but according to the PHP specs there is no space between -f and the email address. >mail('xxx@xxxxx.com','Test Email',$Message,$headers, '-femail@address.com'); Edited April 20, 2007 by carbonize Quote Link to comment Share on other sites More sharing options...
click Posted April 20, 2007 Share Posted April 20, 2007 You're right; There shouldn't be a space. I was going by the sendmail man page on my development system, but now I see that that system is running postfix and its sendmail implementation. The true sendmail doesn't use a space. Sorry 'bout that. Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted April 21, 2007 Share Posted April 21, 2007 Yes, sorry about that, the comma is necessary. And no there should be no space as there is in Perl programming. Quote Link to comment Share on other sites More sharing options...
carbonize Posted April 21, 2007 Share Posted April 21, 2007 Given that I'm about to put this into Lazarus are there any known issues with this? Does it only work on Apache for instance? Quote Link to comment Share on other sites More sharing options...
carbonize Posted April 21, 2007 Share Posted April 21, 2007 Not that it makes a difference on TC servers but the -f parameter will result in an error if the server is in safe mode. Quote Link to comment Share on other sites More sharing options...
click Posted April 21, 2007 Share Posted April 21, 2007 (edited) I assume it won't work under Windows, either. I think you can accomplish the same thing on a Windows system with "ini_set('sendmail_from','email@address.com')". I don't have much experience with php under Windows, though, so you'll want to double check that. Edited April 21, 2007 by click Quote Link to comment Share on other sites More sharing options...
uwptaik Posted April 23, 2007 Author Share Posted April 23, 2007 I want to thank all of you guys for your help, I finally got it to work! $headers = "From: Esteban <esteban@solabroad.com>\r"; $headers .= "Reply-To: Esteban <esteban@solabroad.com>\r"; $headers .= "Return-Path: Esteban <esteban@solabroad.com>\r"; mail ( "$cur_email", "Greetings from Sol Abroad!!", $emailbodycontact, $headers, '-f esteban@solabroad.com'); thank you gentleman! Quote Link to comment Share on other sites More sharing options...
carbonize Posted April 23, 2007 Share Posted April 23, 2007 According to the specs there should be no space between the -f and the email address. Quote Link to comment Share on other sites More sharing options...
uwptaik Posted April 23, 2007 Author Share Posted April 23, 2007 Well, i tested it with the space and it works perfectly! Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted April 23, 2007 Share Posted April 23, 2007 Glad to hear it. Quote Link to comment Share on other sites More sharing options...
jhollin1138 Posted May 12, 2007 Share Posted May 12, 2007 I had a project a month ago or so to add a form to my company's website. My goal was to have the email in both html and plain text as well as include an attachment. I read all the posts on sending mail on php.net and combined the best of the information to build a function for handling mail. Here is the function I came up with, of course there is a little bit of nearly every post in it. >function send_mail($fromname, $emailaddress, $fromaddress, $emailsubject, $body, $fileattach = false) { # Is the OS Windows or Mac or Linux if (strtoupper(substr(PHP_OS,0,3)=='WIN')) $eol="\r\n"; elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) $eol="\r"; else $eol="\n"; $mime_boundary_1 = md5(time()); $mime_boundary_2 = "1_".$mime_boundary_1; $mail_sent = false; # Common Headers $headers = ""; $headers .= 'From: '.$fromname.'<'.$fromaddress.'>'.$eol; $headers .= 'Reply-To: '.$fromname.'<'.$fromaddress.'>'.$eol; $headers .= 'Return-Path: '.$fromname.'<'.$fromaddress.'>'.$eol; // these two to set reply address $headers .= "Message-ID: <".$now."webmaster@".$_SERVER['SERVER_NAME'].">".$eol; $headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters # Boundry for marking the split & Multitype Headers $headers .= 'MIME-Version: 1.0'.$eol; $headers .= "Content-Type: multipart/mixed;".$eol; $headers .= " boundary=\"".$mime_boundary_1."\"".$eol; $msg = ""; # Building Message Body $msg .= "--".$mime_boundary_1.$eol; $msg .= "Content-Type: multipart/alternative;".$eol; $msg .= " boundary=\"".$mime_boundary_2."\"".$eol.$eol; # Text Version $msg .= "--".$mime_boundary_2.$eol; $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol; $msg .= "Content-Transfer-Encoding: 8bit".$eol; $msg .= strip_tags(str_replace("<br>", $eol, $body)).$eol.$eol; # HTML Version $msg .= "--".$mime_boundary_2.$eol; $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol; $msg .= "Content-Transfer-Encoding: 8bit".$eol; $msg .= str_replace($eol, "<br>", $body).$eol.$eol; # Finished Message Body $msg .= "--".$mime_boundary_2."--".$eol.$eol; # Begin Adding Attachments if ($fileattach) { for($i=0; $i < count($fileattach); $i++) { if (is_file($fileattach[$i]["file"])) { # File for Attachment $file_name = substr($fileattach[$i]["file"], (strrpos($fileattach[$i]["file"], "/")+1)); $handle=fopen($fileattach[$i]["file"], 'rb'); $f_contents=fread($handle, filesize($fileattach[$i]["file"])); $f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode(); //Remove file unlink($fileattach[$i]["file"]); # Attachment $msg .= "--".$mime_boundary_1.$eol; $msg .= "Content-Type: ".$fileattach[$i]["content_type"].";".$eol; $msg .= " name=\"".$file_name."\"".$eol; $msg .= "Content-Transfer-Encoding: base64".$eol; $msg .= "Content-Disposition: attachment;".$eol; $msg .= " filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !! $msg .= $f_contents.$eol.$eol; } } } # Finished $msg .= "--".$mime_boundary_1."--".$eol.$eol; // finish with two eol's for better security. see Injection. # SEND THE EMAIL ini_set(sendmail_from, $fromaddress); // the INI lines are to force the From Address to be used ! if (mail($emailaddress, $emailsubject, $msg, $headers)) $mail_sent = true; ini_restore(sendmail_from); return $mail_sent; } I realize this is more then the original post asked for, but I figured it might be useful. Quote Link to comment Share on other sites More sharing options...
carbonize Posted May 12, 2007 Share Posted May 12, 2007 Yeah my Lazarus code is pretty much the same. Curious as to why you have the different eols though as it shouldn't make any difference. Certainly hasn't in my experience. Quote Link to comment Share on other sites More sharing options...
jhollin1138 Posted May 12, 2007 Share Posted May 12, 2007 Yeah my Lazarus code is pretty much the same. Curious as to why you have the different eols though as it shouldn't make any difference. Certainly hasn't in my experience. To be honest I am not sure why I did that either. Some of the code on php.net had them, and others didn't. I am not planning on hosting on a MAC or even Windows so I will never know if I needed them or not. Quote Link to comment Share on other sites More sharing options...
uwptaik Posted May 14, 2007 Author Share Posted May 14, 2007 Dear jhollin1138, Thanks for your reply, that was really helpful. If you don't mind me asking, how will the lines: $headers .= "Message-ID: <".$now."webmaster@".$_SERVER['SERVER_NAME'].">".$eol; $headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters help with Spam filters? This is a big issue for us b/c any emails coming from our account info@solabroad.com to yahoo and gmail are delivered to the inbox, but stinkin' hotmail always puts them in Spam (big issue b/c we have many customer at hotmail) the header I use is: $headers = 'From: "Sol Education Abroad" <info@solabroad.com>' . "\r\n" .'Reply-To: "Sol Education Abroad" <info@solabroad.com>'; mail ( "$cur_email", "Greetings from Sol Abroad!!", $emailbodycontact, $headers, '-f info@solabroad.com'); Any info would be greatly appreciated. regards, Esteban info@solabroad.com Quote Link to comment Share on other sites More sharing options...
jhollin1138 Posted May 14, 2007 Share Posted May 14, 2007 This is a big issue for us b/c any emails coming from our account info@solabroad.com to yahoo and gmail are delivered to the inbox, but stinkin' hotmail always puts them in Spam (big issue b/c we have many customer at hotmail) Being a long time hotmail and yahoo user myself, I think I can answer this. I believe Hotmail doesn't have a a true spam filter like yahoo and the others use. When a hotmail user turns on spam filtering, basically if the email isn't from an address in the address book or the safe list, hotmail will assume the email is spam. The people receiving your email on their hotmail account need to have your email or "@solabroad.com" in their safe list. I believe because of this, there is nothing you can do with formating your email to get around this with hotmail. 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.