Results 1 to 4 of 4

Thread: PHP email formatting issues

  1. #1
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP email formatting issues

    I'm trying to format the data sent to me better in the email.

    Current code that works fine without the formatting is:

    PHP Code:
    <?php  
     $to 
    'brordinbdf@gmail.com' 
     
    $from $_REQUEST['email'] ;  
     
    $name $_REQUEST['CharacterName'] ;  
     
    $headers "From: $from"
     
    $subject "New Insanity Guild Application"
      
     
    $fields = array();  
     
    $fields{"CharacterName"} = "Character Name"
     
    $fields{"ArmoryLink"} = "Battle.net link"
     
    $fields{"CharacterClass"} = "Character Class";  
     
    $fields{"CurrentSpec"} = "Current Spec"
     
    $fields{"CurrentServer"} = "Current Server"
     
    $fields{"CurrentGuild"} = "Current Guild Name"
     
    $fields{"ReasonForLeaving"} = "Reason for leaving current guild";  
     
    $fields{"GuildHistory"} = "List guild history";  
     
    $fields{"Reason"} = "Reason for applying to Insanity";  
     
    $fields{"LookGuild"} = "What you look for in a guild"
     
    $fields{"WwsReportLinks"} = "List WWS/WOL report links";  
      
     
    $fields{"AddNotes"} = "Additional Notes";  
      
     
    $body "We have received the following application:\n\n"; foreach($fields as $a => $b){     $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }  
      
     
    $headers2 "From: noreply@insanity-guild.net";  
     
    $subject2 "Thank you for applying to Insanity of Black Dragonflight";  
     
    $autoreply "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.insanity-guild.net"
      
     if(
    $from == '') {print "You have not entered an email, please go back and try again";}  
     else {  
     if(
    $name == '') {print "You have not entered a name, please go back and try again";}  
     else {  
     
    $send mail($to$subject$body$headers);  
     
    $send2 mail($from$subject2$autoreply$headers2);  
     if(
    $send)  
     {
    header"Location: http://www.insanity-guild.net/thankyou.html" );}  
     else  
     {print 
    "We encountered an error sending your mail, please notify brordinbdf@gmail.com"; }  
     } 

     
    ?>
    Just formatting it would work by I would ultimately like to receive it in html.

    Have been trying to get it done on my own but when I add the headers I come back with an error. So I thought I'd let you guys help from scratch.

    Thanks in advance.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    See example 4. http://php.net/manual/en/function.mail.php

    You can probably just copy their header info over to your file.
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This seems to be what im looking for after I added the headers to allow html but not sure where to add this with my current code.

    PHP Code:
    $message '
    <html>
    <head>
      <title>Birthday Reminders for August</title>
    </head>
    <body>
      <p>Here are the birthdays upcoming in August!</p>
      <table>
        <tr>
          <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
        </tr>
        <tr>
          <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
        </tr>
        <tr>
          <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
        </tr>
      </table>
    </body>
    </html>
    '


    Amended code looks like this:

    PHP Code:
    <?php 
     $to 
    'brordinbdf@gmail.com' ;
     
    $from $_REQUEST['email'] ; 
     
    $name $_REQUEST['CharacterName'] ; 
     
    $headers "From: $from";
     
    $headers .= "MIME-Version: 1.0" "\r\n";
     
    $headers .= "Content-type: text/html; charset=iso-8859-1" "\r\n";
     
    $subject "New Insanity Guild Application";
     
     
    $fields = array(); 
     
    $fields{"CharacterName"} = "<br />Character Name<br />";
     
    $fields{"ArmoryLink"} = "Battle.net link";
     
    $fields{"CharacterClass"} = "Character Class"
     
    $fields{"CurrentSpec"} = "Current Spec";
     
    $fields{"CurrentServer"} = "Current Server";
     
    $fields{"CurrentGuild"} = "Current Guild Name";
     
    $fields{"ReasonForLeaving"} = "Reason for leaving current guild"
     
    $fields{"GuildHistory"} = "List guild history"
     
    $fields{"Reason"} = "Reason for applying to Insanity"
     
    $fields{"LookGuild"} = "What you look for in a guild";
     
    $fields{"WwsReportLinks"} = "List WWS/WOL report links"
     
     
    $fields{"AddNotes"} = "Additional Notes"
     
     
    $body "We have received the following application:\n\n"; foreach($fields as $a => $b){     $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 
     
     
    $headers2 "From: noreply@insanity-guild.net"
     
    $subject2 "Thank you for applying to Insanity of Black Dragonflight"
     
    $autoreply "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.insanity-guild.net";
     
     if(
    $from == '') {print "You have not entered an email, please go back and try again";} 
     else { 
     if(
    $name == '') {print "You have not entered a name, please go back and try again";} 
     else { 
     
    $send mail($to$subject$body$headers); 
     
    $send2 mail($from$subject2$autoreply$headers2); 
     if(
    $send
     {
    header"Location: http://www.insanity-guild.net/thankyou.html" );} 
     else 
     {print 
    "We encountered an error sending your mail, please notify brordinbdf@gmail.com"; } 
     }
    }
     
    ?>
    Last edited by jalowery; 01-22-2011 at 07:44 PM.

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    that's correct; it should work fine.

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
  •