Sending HTML e-mail via PHP formmail

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
TortillaBoy
Forum Newbie
Posts: 2
Joined: Fri Nov 07, 2003 11:56 pm
Location: Colorado

Sending HTML e-mail via PHP formmail

Post by TortillaBoy »

WARNING! Newbie question ahead!!

I have a client who wants to receive in his e-mail the exact form, as filled out by the sender. (i.e. http://www.bistaterubber.com/belt_wizard.html )

How do I send HTML in e-mail using this mail() function?

Code: Select all

$success = mail($your_email_address, $subject, $inside_mail, "From: $name <$email>");
if($success) &#123;
	if($autoresponse == "yes") &#123;
		$response_subject = stripslashes($response_subject);
		$response_mail = stripslashes($response_mail);
		mail($email, $response_subject, $response_mail, "From: $owner_name <$your_email_address>");
	&#125;
	if($after_url == "") &#123;
		// out put send info
		print "<html><head><title>$subject</title>";
		if($css_file != "")
			print "<link rel="stylesheet" type="text/css" href="$css_file">";
		print "</head><body bgcolor=$background_color background=$background_image text=$text_color link=$link_color vlink=$visited_link_color alink=$active_link_color><font face=$font_name size=$font_size>";
		print "The following email has been sent successfully!<br><br><ul>";
		for($i = 0; $i < count($fields); $i++) &#123;
			$actual_var = $fields&#1111;$i];
			if($actual_var == "required_fields" || $actual_var == "after_url" || $actual_var == "check_email_address" || $actual_var == "subject" || $actual_var == "your_email_address" || $actual_var == "env_report" || $actual_var == "background_color" || $actual_var == "background_image" || $actual_var == "text_color" || $actual_var == "link_color" || $actual_var == "visited_link_color" || $actual_var == "active_link_color" || $actual_var == "font_name" || $actual_var == "font_size" || $actual_var == "highlight_color" || $actual_var == "css_file" || $actual_var == "owner_name" || $actual_var == "autoresponse" || $actual_var == "response_subject" || $actual_var == "response_mail")
				print "";
			else &#123;
				$actual_val = stripslashes($HTTP_POST_VARS&#1111;$actual_var]);
				print "<li>$actual_var: $actual_val<br>";
			&#125;
		&#125;
		print "</ul><a href="http://www.tb-designs.com" target="new">TB-Designs.com</a></font></body></html>";
	&#125; else &#123;
	headfunction($after_url);
	&#125;
&#125; else &#123;
	print "<html><head><title>$subject</title>";
	if($css_file != "")
		print "<link rel="stylesheet" type="text/css" href="$css_file">";
	print "</head><body bgcolor=$background_color background=$background_image text=$text_color link=$link_color vlink=$visited_link_color alink=$active_link_color><font face=$font_name size=$font_size>";
	print "<b>Oops</b>, something is wrong with my php server, please send your email <a href="mailto:$your_email_address">here</a>...Sorry, 'bout the inconvenience.</font></body></html>";
&#125;
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

checkout
[google]html email with php[/google]
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Basically the message headers need to be set to text/html instead of the default plaintext.

The link above will show you ways to do this. :)
TortillaBoy
Forum Newbie
Posts: 2
Joined: Fri Nov 07, 2003 11:56 pm
Location: Colorado

Post by TortillaBoy »

Muchas gracias! :)
Post Reply