PDA

View Full Version : Format Of E-mail from a form



srule_
07-13-2007, 10:26 PM
hi,
Is there a way to format the appearance of the info you recive from a form?

For example, i am using the code below, but when i added a radio button to my form, the respons to these feature would not be shown in e-mail I recieved.

I am using the following code to send forms info to my e-mail address:


<?php
#Edit this line for your own e-mail address.
$target_email = 'youremailaddresshere@site.com';

$from_email = '';

# Reduce the possibility of email injection by replacing ill formatting characters in the from address.
$from_email = str_replace(array("\r", "\n"), "", $_POST['address']);

if($from_email != $_POST['address']) silly_error("Invalid email address entry.");

if( empty($from_email) ){
silly_error("You did not supply a valid e-mail address.");
}

$from_email = trim($from_email);

#Handle the message...
$msg = '';
$msg = trim($_POST['current_medication']);

if(empty($msg)) silly_error("You did not insert a message.");

$name = '';

#Handle the name...
$name = str_replace(array("\r", "\n"), '', trim($_POST['firstname']));

if(empty($name)) silly_error("You must enter your name before submitting the form.");

#Mail it!
$mail_headers = 'From: ' . $from_email . "\r\nReply-To: " . $from_email . "\r\n";

$sent = mail($target_email, "Contact from: $name", $msg, $mail_headers);

#Did it send?

if(! $sent) silly_error("Sorry, but your request could not be completed at this time.");


# This function shows your contact page in case of an error, with $msg being bold red.
# Customize the HTML as you'd like, but leave the PHP alone unless you know what you're doing.

function silly_error($msg){

echo <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Web Perfect - Contact </title>
<link rel="stylesheet" type="text/css" href="style2.css" />
</head>
<body id="contact">

<div id="logo"></div>

<div id="wrapper">
<div id="header"></div>

<ul class="nav">

<li> <a href="index.htm" id="homelink"> Home </a> </li>
<li> <a href="about.htm" id="aboutlink"> About Us </a> </li>
<li> <a href="portfolio.htm" id="portfoliolink"> Portfolio </a> </li>

<li> <a href="getasite.htm" id="getasitelink"> Get a Site </a> </li>
<li> <a href="contact.htm" id="contactlink" class="end"> Contact </a> </li>
</ul>

<div id="contentwrap">

<div class="contentsmall">

<!--FORUM-->


<form id="two" action="do-contact.php" method="post">

<fieldset id="contact">
<legend>Contact Us</legend>
<div style="font-weight: bold; color: red;">Error: $msg</div>
<label for="name">Name : </label>
<input name="firstname" id="firstname" type="text" tabindex="2" />
<br />
<label for="address">e-mail : </label>
<input name="address" id="address" type="text" tabindex="3" />

<p class="other">Ask a Question or Leave a Comment here :</p>

<textarea name="current_medication" tabindex="40" cols="40" rows="10"></textarea>
</fieldset>
<p>
<input id="button1" type="submit" value="Send" />
<input id="button2" type="reset" value="Reset" />
</p>
</form>
<!--END OF FORM-->
</div>
</div>

</div>

<div id="footer"><p> Copyright Web-Perfect 2007</p></div>

</body>
</html>
EOF;
exit;
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Web Perfect - Contact </title>
<link rel="stylesheet" type="text/css" href="style2.css" />
</head>
<body id="contact">

<div id="logo"></div>

<div id="wrapper">
<div id="header"></div>

<ul class="nav">

<li> <a href="index.htm" id="homelink"> Home </a> </li>
<li> <a href="about.htm" id="aboutlink"> About Us </a> </li>
<li> <a href="portfolio.htm" id="portfoliolink"> Portfolio </a> </li>

<li> <a href="getasite.htm" id="getasitelink"> Get a Site </a> </li>
<li> <a href="contact.htm" id="contactlink" class="end"> Contact </a> </li>
</ul>

<div id="contentwrap">

<div class="contentsmall">


<fieldset id="contact">
<legend>Contact Us</legend>
<p>Your message has been sent! Thank you for contacting us.
</fieldset>
</div>
</div>

</div>

<div id="footer"><p> Copyright Web-Perfect 2007</p></div>

</body>
</html>

stevenmw
07-13-2007, 11:15 PM
Just add some css and html to or around your $sent variable... Then not only the email content, but the email's appearance will be sent as weel.. And that will make the recieved email look the way you want.