Reputation: 313
I've got a php form and would like to add some css so that the HTML email isn't boring plain text.
$msg = "<h2><strong>EMAIL SUBMISSION FROM</strong></h2><br>" .
PHP_EOL;
$msg .= "your website<br>" . PHP_EOL;
$msg .= "-------------------------------------------------<br><br>" .
PHP_EOL . PHP_EOL;
$msg .= "<strong>Name: </strong>" . PHP_EOL;
$msg .= "$name <br>" . PHP_EOL . PHP_EOL;
$msg .= "<strong>Email: </strong>" . PHP_EOL;
$msg .= "$email <br>" . PHP_EOL . PHP_EOL;
$msg .= "<strong>Contact Number: </strong>" . PHP_EOL;
$msg .= "$phone <br>" . PHP_EOL . PHP_EOL;
$msg .= "<strong>Day in: </strong>" . PHP_EOL;
$msg .= "$dayin <br>" . PHP_EOL . PHP_EOL;
$msg .= "<strong>Day out: </strong>" . PHP_EOL;
$msg .= "$dayout <br><br>" . PHP_EOL . PHP_EOL;
$msg .= "<strong>Notes / Comments: </strong><br>" . PHP_EOL;
$msg .= "$comments" . PHP_EOL . PHP_EOL;
How can I make the "EMAIL SUBMISSION FROM" a different color / font?
I've tried <span style="color:#FF0000;">EMAIL SUBMISSION FROM</span>
and that doesn't work
My Headers:
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/html; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
I'm not sure if anything needs changing in the headers?
Also, at the top of my contact.php file is if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
Must this stay the same?
EDIT
$msg = "<html><body>
<strong>EMAIL SUBMISSION FROM</strong><br>
your website<br>
------------------------------------------------------<br><br>
<strong>Name: </strong>
$name <br>
<strong>Email: </strong>
$email <br>
<strong>Contact Number: </strong>
$phone <br>
<strong>Day in: </strong>
$dayin <br>
<strong>Day out: </strong>
$dayout <br><br>
<strong>Notes / Comments: </strong><br>
$comments
</body></html>";
Upvotes: 0
Views: 419
Reputation: 10371
How can I make the "EMAIL SUBMISSION FROM" a different color / font? I've tried EMAIL SUBMISSION FROM and that doesn't work
color:FF0000
should be color:#FF0000
.
I'm not sure if anything needs changing in the headers?
Headers seem fine.
Also, at the top of my contact.php file is if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n"); Must this stay the same?
Yes, this is fine.
Upvotes: 1
Reputation: 17434
Augh, the code...
Okay, the short(est) answer is:
<strong style="color:#FF0000">.....</strong>
Will work for anything. Slightly better, and supported by most e-mail clients, is to use some inline styles:
<style type="text/css">
.important { color: #ff0000; }
</style>
<strong class="important">....</strong>
This will do the same thing, and now if you want to make something else red later, or if you want to change important things to be orange, you have a single place you can change that.
Finally, with regards to the PHP part... you don't need all those newlines. HTML is whitespace-insensitive, so all they're doing is making your source code prettier. A better format would be something like this:
<?php
$msg = <<<MESSAGE
<h2><strong>EMAIL SUBMISSION FROM</strong></h2><br />
<strong>Name: </strong> $name<br />
<strong>Email: </strong> $email<br />
... etc ...
MESSAGE;
?>
This uses PHP "heredoc" format. You can learn more about it here: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
Upvotes: 1
Reputation: 2337
I found an example for sending emails with css here: http://css-tricks.com/2866-sending-nice-html-email-with-php/
hope it solves your problem :).
Upvotes: 1