Page 1 of 1

Sending HTML e-mail via PHP formmail

Posted: Fri Nov 07, 2003 11:56 pm
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;

Posted: Sat Nov 08, 2003 12:25 am
by qads
checkout
[google]html email with php[/google]

Posted: Sat Nov 08, 2003 2:04 am
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. :)

Posted: Sat Nov 08, 2003 10:48 pm
by TortillaBoy
Muchas gracias! :)