Php mail newline problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lamia
Forum Newbie
Posts: 11
Joined: Sun Jun 19, 2005 2:21 am

Php mail newline problem

Post by lamia »

Hi, I got a functional mail script. I can see no problem with it except that when I try to open the email relayed from my system to my yahoo inbox, the output isn't quite as what is expected... For example I typed this in the textarea
This
is
a
test
!
the output should be...
This
is
a
test
!
well... it doesn't display like that... But instead...

This \r \n is \r \n a \r \n test \r \n !

Uh... any help would be appreciated... And one more thing, I find that my e-mail is always stored in the bulk folder rather than my inbox...

Here's the code...

Code: Select all

ini_set("SMTP","localhost");
     ini_set("smtp_port","26");
     ini_set("sendmail_from","admin@localhost.com");

     $headers  = "MIME-Version: 1.0\n";
     $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
     $headers .= "X-Priority: 3\n";
     $headers .= "X-MSMail-Priority: Normal\n";
     $headers .= "X-Mailer: php\n";
     $headers .= "From: \"".$n."\" <".$e.">\n";

     if (mail("netboysbe@yahoo.com",$s,$m,$headers))
     {
       $message.="<center><p>Success!</p></center>";
     }
     else
     {
       $message.="<center><p>The following errors occured!</p></center>";
       $errmessage.='<p>Unable to send message.</p>';
     }
JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

in your $m the string needs to be in double quotes not single "this \r \n is a test".
lamia
Forum Newbie
Posts: 11
Joined: Sun Jun 19, 2005 2:21 am

Post by lamia »

I'm sorry, I may have made my question vague for you... I used the $m like this...

Code: Select all

$m=null;
     $m.=escape_data($_POST['message']);
and again, here's the code for mailing...

Code: Select all

ini_set("SMTP","localhost");
     ini_set("smtp_port","26");
     ini_set("sendmail_from","admin@localhost.com");

     $headers  = "MIME-Version: 1.0\n";
     $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
     $headers .= "X-Priority: 3\n";
     $headers .= "X-MSMail-Priority: Normal\n";
     $headers .= "X-Mailer: php\n";
     $headers .= "From: \"".$n."\" <".$e.">\n";

     if (mail("netboysbe@yahoo.com",$s,$m,$headers))
     {
       $message.="<center><p>Success!</p></center>";
     }
     else
     {
       $message.="<center><p>The following errors occured!</p></center>";
       $errmessage.='<p>Unable to send message.</p>';
     }
JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

we already see the code for mailing... -_-'

When you escape something, you take away the use of the backslash. i.e. they don't do jack anymore.
lamia
Forum Newbie
Posts: 11
Joined: Sun Jun 19, 2005 2:21 am

Post by lamia »

Hehe yeah I just figured it out! Thanks Guys!
Post Reply