Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Problem formatting PHP-generated E-mail

    In my website, if a Member reports another Member's Profile, then my PHP script sends an e-mail to the Administrator that should look like this...

    2012-12-07 4:36:30pm

    Dear Admin,

    A complaint was made about username1's Member Profile by DoubleDee.

    Here is the complaint...

    "This member has a really disgusting photo in his profile.

    It almost looks like he is naked?!

    He also has some pretty rude things in his Member Bio.

    You should make him take this stuff down!!"

    Here is my PHP code...
    PHP Code:
        // ****************************************
        // E-mail Admin about Reported Profile.        *
        // ****************************************

        
    $emailTo 'AdminDebbie@mail.com';

        
    $headers  "From: Admin <admin@MySite.com>\r\n";
        
    $headers .= "MIME-Version: 1.0\r\n";
        
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

        
    $currTime date('Y-m-d g:i:sa'time());

        
    // Build E-mail.
        
    $subject 'Re: Reported Member Profile  (' $currTime ')';

        
    $body $currTime "\n\n" PHP_EOL;
        
    $body .= "Dear Admin,\r\n\r\n" PHP_EOL;
        
    $body .= "A complaint was made about $user's Member Profile by $sessUsername.\r\n\r\n";
        
    $body .= "Here is the complaint...\r\n\r\n" PHP_EOL;
        
    $body .= "$issue!!\r\n\r\n" PHP_EOL;

        
    mail($emailTo$subject$body$headers); 

    When a Member's files a complaint, the e-mail I get is all on one long line and looks like this...

    "2012-12-07 4:36:30pm Dear Admin, A complaint was made about username1's Member Profile by DoubleDee. Here is the complaint... This member has a really disgusting photo in his profile. It almost looks like he is naked?! He also has some pretty rude things in his Member Bio. You should make him take this stuff down!!"

    What am I doing wrong?

    I also tried the above code without the PHP_EOL thingy and that doesn't help either?!


    BTW, my admin account is in Gmail, and I'm sure this same code was working months ago, but as I am doing final testing on my website, I now see the Admin E-mail is screwed up?!

    Help would be appreciated!!

    Thanks,


    Debbie

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,538
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    Try changing all of this:

    $body = $currTime . "\n\n" . PHP_EOL;
    $body .= "Dear Admin,\r\n\r\n" . PHP_EOL;
    $body .= "A complaint was made about $user's Member Profile by $sessUsername.\r\n\r\n";
    $body .= "Here is the complaint...\r\n\r\n" . PHP_EOL;
    $body .= "$issue!!\r\n\r\n" . PHP_EOL;



    To this:

    $body = "
    $currTime
    ----------------------------
    Dear Admin,
    A complaint was made about $user's Member Profile by $sessUsername.
    Here is the complaint...
    $issue!!
    ";



    When you get the email, it should be formatted
    just like the text layout. No need to add \n or EOL.
    I guess that I should add that I've always done it this
    way with shared webhosts ... maybe Gmail is different?


    .

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    In HTML newlines are collapsed for display. You need to convert those \n characters to <br> tags manually, or leave them and convert the body when you send the message:
    PHP Code:
    mail($emailTo$subjectnl2br($body), $headers); 


  •  

    Posting Permissions

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