Sorry, still a novice but getting better. I'm building a website and because I'm not that good I'm providing a page where club members can report problems and give me enough information to look into it. I have written the PHP code to send me an e-mail. If I echo the $message it prints fine on the screen but in an e-mail it's just one long sentence with the HTML tags in it. I searched for a solution and tried the ""Content-type: text/plain; charset=UTF-8"" but that did nothing. I know I'll be embarrassed when I get the answer but I am stuck. Thanks in advance.
<?php
// Convert form data to srting data
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$e_mail=$_POST['e_mail'];
$browser=$_POST['browser'];
$browser_version=$_POST['browser_version'];
$os=$_POST['os'];
$os_ver=$_POST['os_ver'];
$device=$_POST['device'];
$make=$_POST['make'];
$issue=$_POST['issue'];
// Use string data to create and send e-mail
$to = '*******@*****.com'; // will need to be converted to webmaster@stjoesclub.com
$subject = 'Problem with St. Joseph Web Site';
$message = $first_name . " " . $last_name . " is reporting a problem with the web site. <br><br>" .
"E-mail address: " . $e_mail . "<br><br>" .
"Browser: " . $browser . "<br>" .
"Browser Version: " . $browser_version . "<br><br>" .
"Operating System: " . $os . "<br>" .
"Operating System Version: " . $os_ver . "<br><br>" .
"Device: " . $device . "<br>" .
"Device Make: " . $make . "<br><br>" .
$issue;
// Send e-mail to webmaster
mail($to, $subject, $message, 'From: ' . $e_mail, "Content-type: text/plain; charset=UTF-8");
?>
use Content-Type
as text/html
as below
$eol="
";
# Common Headers
$headers = "Message-ID: <".time()."-".$e_mail.">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
// These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: text/html; charset=iso-8859-1".$eol.$eol;
mail($to, $subject, $message, 'From: ' . $e_mail, $headers);
Content-Type
should be set to text/html
as said by @Ben Fortune
Eureka! Thanks to the help from Harish Singh I was able to solve my own issue. Looking at his code one problem I found was that the string $mailHtml was undefined which was the reason for a blank e-mail.
But learning from his code I figured out the $eol stood for End Of Line. By using that instead of the
the e-mail formats correctly when it comes in via the e-mail.
Unfortunately it doesn't work if I echo the $message on the screen after submission but fortunately I saved the old code so I can print it properly. I know that's not effective code but for a rookie hack it works.
Thanks again for the help.