Log in

View Full Version : PHP email formatting issues



jalowery
01-22-2011, 06:48 PM
I'm trying to format the data sent to me better in the email.

Current code that works fine without the formatting is:


<?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.

bluewalrus
01-22-2011, 07:05 PM
See example 4. http://php.net/manual/en/function.mail.php

You can probably just copy their header info over to your file.

jalowery
01-22-2011, 07:34 PM
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.


$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
$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"; }
}
}
?>

traq
01-22-2011, 09:14 PM
that's correct; it should work fine.