0

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 &#92; question!</div>
<br />
<div id="mBody">
    <b> Email </b>: tester@testmail.net<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 = "test@weeshare.ws"; 
$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 &#92; 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?

Jake Brunton
  • 27
  • 1
  • 9

2 Answers2

2

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.

  • Use inline CSS for better results.
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
0
 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
DWolf
  • 703
  • 1
  • 7
  • 20