PDA

View Full Version : Html Email Form


dahliacreative
08-23-2011, 04:21 PM
Hi I'm trying to create a form to email script that sends the form information in an html format.

Can anyone see why my code wouldn't be working??

<?php

//Check if the form has sent data
if(isset($_POST['submit'])) {

//Create variables
$to = "simon@creative-jar.com";
$subject = "Website Enquiry";
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$message = $_POST['message'];

//Create the body
$body = '<html><body>';
$body .= '<h1>Hello, World!</h1>';
$body .= '</body></html>';

//Create headers
$headers = "From: $name\r\n";
$headers .= "Reply-to: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

//Send the email
if(mail($to, $subject, $body, $headers)) {

//Display Success Message
echo '<p class="success">Thank you, your message has been sent successfully. Some one will be in touch within 48hours.</p>';

} else {

//Display Success Message
echo '<p class="error">There has been a problem delivering your message, please try again.</p>';

};

};
?>

<form method="post" action="mail.php">
<input type="text" name="name" />
<input type="text" name="email" />
<input type="text" name="telephone" />
<textarea name="message"></textarea>
<input type="submit" value="submit" name="submit" />
</form>

edbr
08-24-2011, 04:06 AM
$body = '<html><body>';
$body .= '<h1>Hello, World!</h1>';
$body .= '</body></html>';
you have to include form posts in the body

dahliacreative
08-24-2011, 04:23 PM
I've got the form emailing,
But the headers are coming all weird. Can anyone see where I'm going wrong???

<?php
//Check if the form has sent data
if(isset($_POST['submit'])) {
//Create variables
$to = "dahliamurder@hotmail.com";
$subject = "Website Enquiry";
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$message = $_POST['message'];

//Create the body
$body = '<html><body><table width="100%" bgcolor="#BBD3CD">';
$body .= '<tr><td align="center"><table width="600" bgcolor="#FDFAF4"><tr><td align="left">';
$body .= '<img src="logo.jpg" alt="Decadent Cakes"/>';
$body .= '<p><strong>Client Name:</strong> '.$name.'</p>';
$body .= '<p><strong>Client Email:</strong> '.$email.'</p>';
$body .= '<p><strong>Client Telephone:</strong> '.$telephone.'</p>';
$body .= '<p><strong>Client Message:</strong></p>';
$body .= '<p>'.$message.'</p>';
$body .= '</td></tr></table></td></tr>';
$body .= '</body></html></table>';

//Create headers
$headers = "From: $name\r\n";
$headers .= "Reply-to: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

//Send the email
if(mail($to, $subject, $body, $headers)) {
//Display Success Message
echo '<p id="success">Thank you, your message has been sent successfully. Some one will be in touch within 48hours. <a href="#">Close</a></p>';
} else {
//Display Success Message
echo '<p id="error">There has been a problem delivering your message, please try again. <a href="#">Close</a></p>';
};
};
?>

edbr
08-25-2011, 01:50 AM
$headers="Content-Type: text/html; charset=windows-1252 \n";
$headers.="From: $name \n";
$headers .= "Reply-to: $email \n"
$headers.="X-mailer:";
try this