Solved

PHP Mail script not being send as HMTL

Posted on 2012-03-27
5
351 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
Comment Utility
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
Comment Utility
MadShiva - Thanks for the reply, but that has made no difference?
0
 
LVL 10

Accepted Solution

by:
MadShiva earned 400 total points
Comment Utility
<?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
Comment Utility
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
Comment Utility
Many thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
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.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now