Page 1 of 1

PHP Form to HTML mail script

Posted: Thu May 17, 2007 7:39 pm
by elysium
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi All, I am a newbie here.  I am hoping that someone from this forum can give me a hand with the PHP problem I'm having.

The code below works fine.  It sends an email after a user has registered.  However, I would like the email to be in HTML and I have no clue how to modify the code.  

Thank you in advance for anyone who responds.

Code: Select all

$to = $_REQUEST['email'] ; 
$from = "a@somehwere.com" ;
$headers = "From:  a@somehwere.com";
$subject = "Thank you for registering";

$fields = array(); 
$fields{"company"} = "Company Name"; 
$fields{"contact"} = "Contact Name";
$fields{"email"} = "Email"; 
$fields{"website"} = "Website URL"; 
$fields{"phone"} = "Phone No."; 
$fields{"fax"} = "Fax No."; 
$body = 

"Dear Sir,

We have received the following information:\n\n"; 
foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$send = mail($to,$subject, $body, $headers);

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu May 17, 2007 7:48 pm
by thiscatis
add

Code: Select all

$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";
$headers .= "MIME-Version: 1.0 ";

Posted: Thu May 17, 2007 8:32 pm
by feyd
Do yourself a favor and use Swiftmailer. It'll save you a boatload of time and pain. It shouldn't be too difficult to find the website ;)