SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: PHP's mail()

  1. #1
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP's mail()

    I have 2 questions :

    1) I've put a newline character (\n) in the mail's body , but when i send the e-mail to someone it shows as \n not a newline. Why is that?

    2) Single quotes appear with a backslash before them (i.e : "don\'t , won\'t ..etc") , how do i remove them? (stripslashes() didn't work)


    thanks for your time

  2. #2
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

  3. #3
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Write down what exactly have you written, and may be then you will get some answers.

  4. #4
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $to 'some@email.com';
    $subject ' test email';
    $header 'From: [email]whatever@email.com[/email]';

    // the next line will show as :
    // "This shouldn\'t \n appear on \n one line"
    // when i view it in my e-mail

    $body "This shouldn't \n appear on \n one line";

    stripslashes($body);

    mail($to$subject$body$header); 

  5. #5
    SitePoint Enthusiast michelangelo's Avatar
    Join Date
    May 2005
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds like a magic quotes problem. Try turning them off using a .htaccess file, or in the PHP ini, and see how you go.

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2004
    Location
    UK
    Posts
    2,670
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    You also will want to change the stripslashes bit to

    Code:
    $body = stripslashes($body);

  7. #7
    SitePoint Addict Quaint's Avatar
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by shadowbox
    You also will want to change the stripslashes bit to

    Code:
    $body = stripslashes($body);
    LOL, yeah, you should want to do that

    Quaint Tech
    - Blog on web development and web technology.

  8. #8
    SitePoint Evangelist djdykes's Avatar
    Join Date
    Feb 2005
    Location
    Chester, Cheshire
    Posts
    565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for newlines try adding in \r\n instead of just \n

    also, it's worth notiing that the message body of most emails is 70 characters, so i would run it through the wordwrap function as well...

    also

    PHP Code:
    $body "This shouldn't \n appear on \n one line"
    the \' doesn't need to be there as you are inside a double quoted string. Thus the single quote does not need to be escaped.

    PHP Code:

    $body 
    "this is a ' single quote";

    echo 
    $body;

    // should appear as
    // this is a ' escaped single quote 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •