Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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

Posted

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.

Posted

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

Posted

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.

  • 2 weeks later...
Posted

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";

Posted

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");

Posted

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.

Posted (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 by carbonize
Posted

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.

Posted (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 by click
Posted

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!

  • 3 weeks later...
Posted

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.

Posted

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.

Posted
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.

Posted

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

Posted
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.

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...