Reputation: 27
So, bascially I'm trying to get an email to send from a support form, and when it sends I want it to use a specified CSS file and html. The message sends and all of the PHP sector is complete, but this is how the email appears:
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://jake-brunton.com/wtf/corner/contact/mailerCss.css">
</head>
<body>
<div id="top">A new query \ question!</div>
<br />
<div id="mBody">
<b> Email </b>: [email protected]<br />
<b> Subject </b>: Test Subject<br />
<b> Name </b>: Jake Bdawg<br />
<b> Message</b>: <br /> Jkat is my other name
</div>
</body>
</html>
This is my first time trying something like this aswell. I already use the escape slash in PHP to make sure the quotations do not mess anything up, but I still can't get it to display in HTML. Here's the PHP file:
<?php
$email = $_POST['email'];
$subjectName = $_POST['subject'];
$name = $_POST['name'];
$messageText = $_POST['message'];
$to = "[email protected]";
$from = " $email ";
$subject = " $subject ";
$message ="<html>
<head>
<link rel=\"stylesheet\" type=\"text/css\" href=\"http://jake-brunton.com/wtf/corner/contact/mailerCss.css\">
</head>
<body>
<div id=\"top\">A new query \ question!</div>
<br />
<div id=\"mBody\">
<b> Email </b>: $email<br />
<b> Subject </b>: $subjectName<br />
<b> Name </b>: $name<br />
<b> Message</b>: <br /> $messageText
</div>
</body>
</html>";
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: $from\r\n";
mail($message);
echo "<center>Message Sent Successfully! We\'ll reply within 2 to 4 business days. Please return to the <a href=\"http://jake-brunton.com/wtf/corner\">Home page</a>";
?>
Anyone know what's wrong here?
Upvotes: 0
Views: 1552
Reputation: 74216
Your headers are incorrect.
Base yourself on the following:
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
as per the manual on mail()
and headers()
http://php.net/manual/en/function.mail.php
Also, do keep in mind that many email services will ignore your stylesheet, especially Google.
Upvotes: 2
Reputation: 725
htmlspecialchars_decode($message);
will allow special html characters to be placed in the string
and a content type of :
Content-Type: text/plain; charset=us-ascii
Upvotes: 0