I have a Problem with Outlook 2010.
I sent an E-Mail with a Contactform with this Code:
$message = '
<html>
<head>
<title>Anfrage ('.$cfg->get('global.page.title').')</title>
<style type="text/css">
body { background:#FFFFFF; color:#000000; }
#tbl td {
background:#F0F0F0;
vertical-align:top;
}
#tbl2 td {
background:#E0E0E0;
vertical-align:top;
}
</style>
</head>
<body>
<p>Mail von der Webseite '.$cfg->get('global.page.title').'</p>
<table id="tbl">
<tr>
<td>Absender</td>
<td>'.htmlspecialchars($_POST['name']).' ('.htmlspecialchars(trim($_POST['email'])).')</td>
</tr>
<tr id="tbl2">
<td>Betreff:</td>
<td>'.htmlspecialchars($_POST["topic"]).'</td>
</tr>
<tr>
<td>Nachricht:</td>
<td>'.nl2br(htmlspecialchars($_POST["message"])).'</td>
</tr>
</table>
</body>
</html>';
$absender = $_POST['name'].' <'.$_POST['email'].'>';
$header = "From: $absender\n";
$header .= "Reply-To: $absender\n";
$header .= "X-Mailer: PHP/" . phpversion(). "\n";
$header .= "X-Sender-IP: " . $_SERVER["REMOTE_ADDR"] . "\n";
$header .= "Content-Type: text/html; Charset=utf-8";
$send_mail = mail($cfg->get('contact.toMailAdress'), "Anfrage (".$cfg->get('global.page.title').")", $message, $header);
//$send_mail = mail("jonathan.sigg#studcom.ch", "Anfrage (".$cfg->get('global.page.title').")", $message, $header);
$_SESSION['kontakt_form_time'] = time();
$tpl->assign("mail_sent", $send_mail);
When I sent the email, doesn't shows the message. it generates a File named [NAME].h. The Message is in this File. How can I fix that, that the message shows in the E-Mail. Is this a Problem about the settings in Outlook?
The problem is with your security settings in Outlook. You need to change the settings to display HTML.
Be careful though, other people trying to read this message will have the same problem. It's common courtesy to offer a plain text version in addition to a HTML version so those that receive these emails don't have to compromise their security settings for you. There's a good chance messages like this can be marked as Spam too.
Good luck.
Related
The HTML consists of simple input fields as listed in the php below, what happens is PHP mail() sends the email but excludes the form data itself. I have spent a lot of time but not sure why this is happening.
and the php to send the mail:
<?php
$to = "user#gmail.com";
$subject = "Question Bank - New Question";
$message = '<html>
<head>
<title>New Question</title>
<style>
table {
border: 1px solid black;
}
table th, tr{
text-align:center;
}
</style>
</head>
<body>
<table cellspacing="20px">
<tr>
<th>Username</th>
<th>Email</th>
<th>Question</th>
<th>Question Hint</th>
<th>Correct Answer</th>
</tr>
<tr>
<td>'.$_POST["username"].'</td>
<td>'.$_POST["email"].'</td>
<td>'.$_POST["question"].'</td>
<td>'.$_POST["questionhint"].'</td>
<td>'.$_POST["answer"].'</td>
</tr>
</table>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: user#company.com' . "\r\n";
$headers .= 'Cc: cc#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
Some email providers like gmail do not support css classes when sending html email through php, so I thought i would store css classes or even full codes in php strings so I can use them multiple times. For example
$leftbox = '<div style="background:#333;border:1px solid #000;padding:5px 2px;float:left;width:200px;">';
$rightbox = '<div style="background:#FFF;border:1px solid #CCC;padding:5px 2px;float:right;width:200px;">';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = '<html><body style="background:#000;margin:auto;width:400px;">';
$message .= $leftbox.'Name </div>'.$rightbox.' Content 1</div>';
$message .= $leftbox.'Addresss </div>'.$rightbox.' Content 2</div>';
$message .= $leftbox.'Mobile </div>'.$rightbox.' Content 3</div>';
mail("emailadress#email.com", "Subject", $message, $headers);
Is this a good idea, or is there any other good ways to do this if you want a good looking html email sent with php?
What is wrong with an inline style sheet? For example:
<!DOCTYPE html><html>
<head>
<style type="text/css">
body {
background:#000;
margin:auto;
width:400px
}
.leftBox {
background:#333;
border:1px solid #000;
padding:5px 2px;
float:left;
width:200px
}
</style>
</head>
<body>
<div class="leftBox">Something in the left box</div>
</body>
</html>
Edit:
Just had a look at some HTML email on 'Inbox' and you may need to include a <!DOCTYPE html>tag. Other than that, the above code "works for me".
I have code to send HTML email via PHP. It has a table. I want to bold the rounded in the screenshot. But the arrived email to Gmail is not showing bold and other changes that should be applied to the class selector of "about".
received email screenshot
Can I use class or ID selector in my style sheet in PHP HTML emails? I do not like to use inline CSS because it is inefficient. I have used them between body.
Here is the code;
$to = "xxxx#gmail.com, xxxx#gmail.com"; //multiple recipients with comma separated
$subject = "Here is the subject"; //cannot contain newline characters
$message = "<h1>This is Heading H1</h1>";
$message .= "This is my <b>first</b> line of text.<br>This is my <b>second</b> line of text<br><br>"; //each line should be separated with (\n).
$message .= "<html>
<head>
<style>
body{
color:#000000;
background-color:#FFFFFF;
font-family:arial, verdana, sans-serif;
}
h1{
font-size:18px;
}
p{
font-size:12px;
}
table{
background-color:#efefef;
border-style:solid;
border-width:1px;
border-color:#999999;
}
th{
background-color:#cccccc;
font-weight:bold;
padding:5px;
}
td{
padding:5px;
}
td.about{
font-family:courier, courier-new, serif;
font-weight:bold;
}
</style>
</head>
<body>
<table>
<tr>
<th> About </th>
<th> Description </th>
</tr>
<tr>
<td class=\"about\"> Name </td>
<td> Andreas </td>
</tr>
<tr>
<td class=\"about\"> Address </td>
<td> Germany </td>
</tr>
<tr>
<td class=\"about\"> Message </td>
<td> I like your 8 day tour package. What are the rates? </td>
</tr>
</table>
</body>
</html>
";
//headers like From, Cc, Bcc, Reply-to, Date ???????????
//$header = "From:raveen1231#gmail.com \r\n";
$header = "From: RXXXXX CXXXXX <rxxxx1111#gmail.com> \r\n"; //additional headers should be separated with (\r\n)
//$header .= "Cc: rxxxxx111#gmail.com \r\n";
//$header .= "Bcc: rxxxxx222#gmail.com \r\n";
//always specify MIME version, content type, and character set when sending HTML email
$header .= "MIME-Version: 1.0 \r\n";
$header .= "Content-type:text/html;charset=UTF-8 \r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; //////////////////////////////Pls Delete later
$retval = mail( $to, $subject, $message, $header );
if( $retval == true ){
echo "Message sent successfully";
}
else{
echo "Message could not be sent!";
}
HTML emails are notoriously tricky to get correct; each email client will handle styling in a different manner. Quoting from Lee Munroe's Things I've Learned About Building & Coding HTML Email Templates (emphasis is the author's):
Email clients use different rendering engines to render HTML emails:
Apple Mail, Outlook for Mac, Android Mail and iOS Mail use WebKit
Outlook 2000/02/03 use Internet Explorer
Outlook 2007/10/13 use Microsoft Word (yes, Word!)
Web clients use their browser's respective engine e.g. Safari uses WebKit, Chrome uses Blink
Gmail strips out <link> tags and any CSS in the <style> tags, and any other CSS that isn't inlined. Not just Gmail web but also the native Gmail mobile apps.
To directly answer your question, Gmail strips out any <style> tags, so you will need to inline your CSS into your HTML elements.
There are a few web services that can inline CSS for you, such as
MailChimp
ZURB Foundation for Emails
Furthermore, you can inline it using a library such as CssToInlineStyles so as to handle it purely within your code.
$mail_body = '<html>
<body style="background-color:#CCC; color:#000; font-family: Arial, Helvetica, sans-serif; line-height:1.8em;">
<h3><img src="http://i.imgur.com/OODKT9h.png" alt="GR" width="194" height="123" border="0">
</h3>
<p>Hello ' . $name . ',</p>
<p>You can make this out to be just like most any web page or design format you require using HTML and CSS.</p>
<p>Grill on the Rock </p>
<hr>
<p>To opt out of receiving this newsletter, click here and we will remove you from the listing immediately.</p>
</body>
</html>';
$to = "$email";
$subject = "Example Grill on the Rock Email";
$from="info#grillontherock.com";
$mail_result = mail($to, $subject, $mail_body, "From:".$from);
}
if($mail_result){
echo "Email has been sent successfully";
}
I am having problem with sending email with php and html.
This code works perfectly fine but the email I am getting is
but when I use double quotation for html file php code greys out for some reason.
$mail_body = "<html>
<body style="background-color:#CCC; color:#000; font-family: Arial, Helvetica, sans-serif; line-height:1.8em;">
<h3><img src="http://i.imgur.com/OODKT9h.png" alt="GR" width="194" height="123" border="0">
</h3>
<p>Hello ' . $name . ',</p>
<p>You can make this out to be just like most any web page or design format you require using HTML and CSS.</p>
<p>Grill on the Rock </p>
<hr>
<p>To opt out of receiving this newsletter, click here and we will remove you from the listing immediately.</p>
</body>
</html>";
$to = "$email";
$subject = "Example Grill on the Rock Email";
$from="info#grillontherock.com";
$mail_result = mail($to, $subject, $mail_body, "From:".$from);
}
if($mail_result){
echo "Email has been sent successfully";
}
a bit new to php and html and I could not find similar problem at the moment.
Also, Is it possible to have email as html form and bring that html through send php file?
You need to set Content-Type to text/html in mail headers
Example headers with Content Type:
$headers = "From: danny#danny.domain\r\n";
$headers .= "Reply-To: no-reply#danny.domain\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
then
$mail_result = mail($to, $subject, $mail_body, $headers);
#edit.
Also check exaple #4 at:
http://php.net/manual/en/function.mail.php
With second html you are having problem with double quotes, because you are using double quotes inside the html, try to escape them. Try this:
or try the link below:
What is the difference between single-quoted and double-quoted strings in PHP?
You need to set Content-Type to text/html in mail headers to send your mail as html mail.
Example headers:
$headers = "From: mymail#gmail.com\r\n";
$headers .= "Reply-To: no-reply#mymail.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
finally after your content you need to send mail like the following.
$mail_result = mail($to, $subject, $mail_body, $headers);
Then for your double quotes problem : here you used double quotes inside double quotes. if that so you need to escape it with "/".
This question already has answers here:
Send HTML in email via PHP
(8 answers)
Closed 7 years ago.
I am setting up a confirmation email script for our customers to receive an email when they complete the online form. I uploaded my script and tested but I received an email with just the raw HTML. I have been looking at some tutorials trying to do this as well. I validated my HTML and I passed all the tests. Is there something that I have to include in my PHP for my body string to be interpreted as HTML?
Here is my script
<?php
//Script for sending a confirmation email
$body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
<title>Demystifying Email Design</title>
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>
</head>
<body style=\"margin: 0; padding: 0; background-color: #ecf0f1;\">
<table cellpadding=\"0\" cellspacing=\"0\" width=\"60%\" align=\"center\" style=\"border: 1px solid #bdc3c7;\">
<tr bgcolor=\"#3498db\">
<td align=\"center\">
<img alt=\"Logo\" src=\"http://www.****.com/logo-lg.jpg\" style=\"width: 50%; height: auto; padding-top: 5%; padding-bottom: 5%;\" />
</td>
</tr>
<tr bgcolor=\"#ffffff\" align=\"center\">
<td>
<h3 style=\"padding-top: 5%; padding-bottom: 5%;\">Worldwide innovator in flexible liquid packaging</h3>
</td>
</tr>
<tr align=\"center\" bgcolor=\"#ffffff\">
<td>
<h4 style=\"padding-top: 5%; padding-bottom: 5%;\">Thank you for contacting customer service. We've received your sample request; one of our team members will be in contact with you in the very near future. Thanks again for your time and interest.</h4>
</td>
</tr>
</table>
</body>
</html>";
$to = "*******#****.com";
$subject = "Thanks for Reaching out";
if (mail($to,$subject,$body)){
echo "Mail was sent";
} else{
echo "Failed";
}
This is the email I received
You need to also set a header indicating this is HTML, e.g.
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to, $subject, $message, $headers);
Source (see Example 3).
Correct code will be:
$to = "*******#****.com";
$subject = "Thanks for Reaching out";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
if (mail($to,$subject,$body,$headers)){
echo "Mail was sent";
}