Solved

PHP Mail script not being send as HMTL

Posted on 2012-03-27
5
355 Views
Last Modified: 2012-03-27
See the below form script. Why am I receiving the email as plain text and not HTML?

<?php

// Convert POST data
$order_no = ( isset($_POST['Order_No']) ) ? $_POST['Order_No'] : '';
$name = ( isset($_POST['Name']) ) ? $_POST['Name'] : '';

$to = 'info@petewinter.com';
$from = 'Foster and Partners';
$subject = 'Foster and Partners Order from Website';

// Headers
$headers = "MIME-Version: 1.0rn"; 
$headers .= "Content-type: text/html; charset=iso-8859-1rn"; 
$headers .= 'From: ' . $from . "\r\n"; 

// Message
$message = "<html><head></head><body>\r\n";
$message.= "Customer Details:\n\n"
			. "Order No: <strong>" . $order_no . "</strong>\n\n"
			. "Name: <strong>" . $name . "</strong>\n\n";
$message.="</body></html>";

mail($to, $subject, $message, $headers);

// Redirect
header('Location: contact_confirmation.php');

?>

Open in new window

0
Comment
Question by:petewinter
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:MadShiva
ID: 37770896
Dear,

This is wrong :

$headers .= "Content-type: text/html; charset=iso-8859-1rn"; 

Open in new window


Should be :

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Open in new window


Regards
0
 

Author Comment

by:petewinter
ID: 37770923
MadShiva - Thanks for the reply, but that has made no difference?
0
 
LVL 10

Accepted Solution

by:
MadShiva earned 400 total points
ID: 37771024
<?php

// Convert POST data
$order_no = ( isset($_POST['Order_No']) ) ? $_POST['Order_No'] : '';
$name = ( isset($_POST['Name']) ) ? $_POST['Name'] : '';

$to = 'info@petewinter.com';

$from = 'Foster and Partners';
$subject = 'Foster and Partners Order from Website';

// Headers
$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers .= 'From: ' . $from . "\r\n"; 

// Message
$message = "<html><head></head><body>\r\n";
$message.= "Customer Details:\n\n"
			. "Order No: <strong>" . $order_no . "</strong>\n\n"
			. "Name: <strong>" . $name . "</strong>\n\n";
$message.="</body></html>";

mail($to, $subject, $message, $headers);

// Redirect
header('Location: contact_confirmation.php');

?>

Open in new window



There was also one error with the line :

$headers = "MIME-Version: 1.0\r\n";


Regards
0
 
LVL 36

Assisted Solution

by:Loganathan Natarajan
Loganathan Natarajan earned 100 total points
ID: 37771173
There is easy library to send as HTML mails. please ref.
http://phpmailer.worxware.com/
http://phpmailer.worxware.com/index.php?pg=examples
0
 

Author Closing Comment

by:petewinter
ID: 37771340
Many thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question