?
Solved

PHP Mail script not being send as HMTL

Posted on 2012-03-27
5
Medium Priority
?
361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Tobias
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:
Tobias earned 1600 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 400 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

765 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