Solved

PHP Mail script not being send as HMTL

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

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…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

739 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