php - Contact form HTML mail styling -
i'm trying style incoming emails sent via self made php contact form.
there 1 slight problem, when receive e-mail in inbox, html displayed static text instead of code.
anyone can help me out?
<?php $name = $_post['name']; $email = $_post['email']; $message = $_post['message']; $from = 'from: info@epicconcepts.nl'; $to = 'info@epicconcepts.nl'; $subject = 'contact formulier bericht'; $human = $_post['human']; $headers = "from: " . strip_tags($_post['req-email']) . "\r\n"; $headers .= "reply-to: ". strip_tags($_post['req-email']) . "\r\n"; $headers .= "cc: quincynorbert@live.nl\r\n"; $headers = 'mime-version: 1.0' . "\r\n"; $headers .= 'content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = '<!doctype html> <html> <head> <style type="text/css"> body{background: #edebea;} #naam{background:#222222;border:4px solid #ddd;width:650px;} #mail{background:#222222;border:4px solid #ddd;width:650px;} #message{background:#222222;border:4px solid #ddd;width:650px;} </style> </head> <body> <div id="naam">'.$name.'</div> <div id="mail">'.$email.'</div> <div id="message">'.$message.'</div> </body> </html>'; if ($_post['submit']) { if ($name != '' && $email != '') { if ($human == '4') { if (mail ($to, $subject, $message, $from)) { echo '<p class="correct-message">your message has been sent!</p>'; } else { echo '<p class="correct-message">something went wrong, go , seek again!</p>'; } } else if ($_post['submit'] && $human != '4') { echo '<p class="correct-message">you answered anti-spam question incorrectly!</p>'; } } else { echo '<p class="correct-message">you need fill in required fields!</p>'; } } ?>
thanks in advance
your headers contained in string $headers
don't pass mail service function, passing $from
html , mime headers never sent why plain text email:
if (mail ($to, $subject, $message, $from)) { // ^ should $headers
change to:
if (mail ($to, $subject, $message, $headers)) {
also, mime header erases current list of headers because didn't include concatenation .
character, alter to:
$headers .= 'mime-version: 1.0' . "\r\n"; // ^ don't forget
finally, should avoid using <style>
css blocks in html emails, not email clients read css blocks, read css if it's defined inline style=""
attribute straight on element.
edit: hardcode header use:
$headers = "from: info@mycompany.com\r\n";
be sure prepare concatenation error pointed out above, otherwise from
header overwritten , not sent.
php html email html-email styling
No comments:
Post a Comment