PHP Form to HTML mail script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
elysium
Forum Newbie
Posts: 1
Joined: Thu May 17, 2007 7:25 pm
Location: Vancouver, Canada

PHP Form to HTML mail script

Post 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]
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

add

Code: Select all

$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";
$headers .= "MIME-Version: 1.0 ";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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 ;)
Post Reply