Re: mail() silly question

From: Date: Sat, 01 Sep 2007 13:17:23 +0000
Subject: Re: mail() silly question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-261589@lists.php.net to get a copy of this message
On 9/1/07, Rodrigo Poblanno Balp <balpo@gmx.net> wrote: > I have a question that might be too silly for those of you who are PHP > gurus. > > Here it comes: > > I had a mail (specifically in the headers) function call like this: > > $header = ""; > $header .= 'From: info@villaarmonica.org.mx\r\n"; > $header .= 'MIME-Version: 1.0\r\n"; > $header .= 'Content-type: text/html; charset=iso-8859-1\r\n"; > $header .= "Reply-To: ".utf8_decode($nombreVar)." > ".utf8_decode($apellidosVar)."<$mailVar>\r\n"; > $header .= "X-Mailer: PHP/".phpversion()."\r\n"; > $header .= "X-Priority: 1"; > > and the mail(...) function always returned TRUE, but the mail was NOT sent. > > After hours of... trial/error debugging, I noticed from an example that > it should be: > > $header = ""; > $header .= 'From: info@villaarmonica.org.mx' . "\r\n"; > $header .= 'MIME-Version: 1.0' . "\r\n"; > $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; > $header .= "Reply-To: ".utf8_decode($nombreVar)." > ".utf8_decode($apellidosVar)."<$mailVar>\r\n"; > $header .= "X-Mailer: PHP/".phpversion()."\r\n"; > $header .= "X-Priority: 1"; > > Question: > > Why? What's the real difference between > $header .= 'From: info@villaarmonica.org.mx' . "\r\n"; > and > $header .= 'From: info@villaarmonica.org.mx\r\n"; Actually that's a parse error ;) You have a single quote at the start and double at the end. Anyway, the reason is interpolation. See http://www.php.net/manual/en/language.types.string.php Under "Single quoted": .. escape sequences for special characters will not be expanded when they occur in single quoted strings. So you end up with a literal '\r\n' at the end of the line, not an actual carriage return & newline that you expect. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#261589) next »