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]<?php
$to = ‘[email protected]’ ;
$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: [email protected]”;
$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 [email protected]”; }
}
}
?> [/php]

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.

Amended code with headers:

[php]<?php
$to = ‘[email protected]’ ;
$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”} = “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: [email protected]”;
$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 [email protected]”; }
}
}
?>[/php]

Problem is now I’m not sure where to put my html.

Also instead of getting the “$from” value of the email address they entered I get “1.0” in the receiving email I get from the script.

First off, your $field array must have brackets ‘[ ]’ instead of curly braces ‘{ }’ it won’t work as it is now. Second, what type of HTML do you want to add?

[php]function validEmail($email)
{

$isValid = true;
$atIndex = strrpos($email, “@”);
if (is_bool

($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email,

$atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen

= strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
// local part length

exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{

// domain part length exceeded
$isValid = false;
}
else if ($local[0] == ‘.’ ||

$local[$localLen-1] == ‘.’)
{
// local part starts or ends with ‘.’
$isValid =

false;
}
else if (preg_match(’/…/’, $local))
{
// local part has two consecutive

dots
$isValid = false;
}
else if (!preg_match(’/^[A-Za-z0-9-.]+$/’, $domain))
{

  // character not valid in domain part
     $isValid = false;
  }
  else if (preg_match

(’/…/’, $domain))
{
// domain part has two consecutive dots
$isValid = false;

}
else if
(!preg_match(’/^(.|[A-Za-z0-9!#%&`_=/$’*+?^{}|~.-])+$/’,
str_replace

("","",$local)))
{
// character not valid in local part unless
// local part is

quoted
if (!preg_match(’/^"("|[^"])+"$/’,
str_replace("","",$local)))
{

    $isValid = false;
     }
  }
  if ($isValid && !(checkdnsrr($domain,"MX") || 

checkdnsrr($domain,“A”)))
{
// domain not found in DNS
$isValid = false;
}
}

return $isValid;
}
[/php]
You can find some PHP email scripts at this page.

Sponsor our Newsletter | Privacy Policy | Terms of Service