Solved

PHP Mail script not being send as HMTL

Posted on 2012-03-27
5
356 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

756 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