Log in

View Full Version : display email as html email



stealthmode666
12-15-2008, 04:02 PM
I have a form which I process by php and send to an email on submit.
I want the email to diplay as HTML.(email client has no problem receiving and displaying html, I know about this part)

At present I have the fields displayed as an array in the email.
I have read how to tell the file to display as html but in the tutrial I'm not sure where to put the code in my script. Also once I do this, how can I have one of the fields of data I process to show in the email as formated html?



$to = ( isset ($_REQUEST['sendto']) ? $_REQUEST['sendto'] : "default 'to' email goes here" );
$from = ( isset ($_REQUEST['Email']) ? $_REQUEST['Email'] : "default 'from' email goes here" ) ;
$name = ( isset ($_REQUEST['Member_Name']) ? $_REQUEST['Member_Name'] : "Default member name goes here" ) ;
$headers = "From: $from";
$subject = "Members ......";


$fields = array();
$fields{"Member_Name"} = "Members Name"
$fields......

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

$headers2 = "From: ...@..";
$subject2 = "Thank-you...";
$autoreply = "Somebody ....Thank-you";
if($from == '') {print "....";}
else {
if($name == '') {print "....";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send){header( "Location: http://www./../thankyou.html" );}
else
{print "......"; }
}
}
?>

The code, tutorials and books I'm lookinh at show how to send an html email but how do I include it in this script above?



<?php
$random_hash = md5(date('r', time()));
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>

--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>


The above tutorial just sends "Hello World" as a H2 formatted header.

So I'm asking how to include some of this code to my above script and take my fields in my array and format them in html to display in the email?