gmail is not displaying html text properly - php

I made script that sends html email messages to users. However, in Gmail, I can't seem to get the font color working. It works for the first message, but the next messages in the conversation are all displayed in purple.
It only happens when I get the strings from .txt files using file_get_Contents()). If I fill the variables with strings from within my class or enter the message directly rather than using variables gmail displays the html normally. I haven't found any problems with other webmail or mail clients. For the actual sending of the mail I tried both phpmailer and the regular mail() function.
$message = "<html><body><font face='Georgia, Times' color='red'>";
$message .= "<p>Beste " . $this->name . "</p>";
$message .= "<p>" . $parPersonal . "</p>";
$message .= "<p>" . $parOne . "</p>";
$message .= "<p>" . $parTwo . "</p>";
$message .= "<p>" . $parThree . "</p></font></body></html>";
A screenshot from gmail:
On a side note, this script will usually only send 1 email to 1 person at a time and this problem shouldn't appear, it is currently just mailing to my own gmail account for testing purposes. However, I'm extremely curious how I can fix this for future purposes.

Most likely this is due to the improper nesting of the <font> tag.
The <font> tag is an inline element, which should be nested inside your block elements such as the <p> tags.
This leads to very messy HTML, but such is the lot with the rather archaic html engines used by email clients.
You can get good coverage these days using inline styles in your elements (but separate <style> blocks are still poorly covered). See this great resource from CampaignMonitor for what you can use : http://www.campaignmonitor.com/css/

Don't use the <font> tag. That's how you styled html in 1995. Instead try using inline styles:
<p style="color: red; font-family: Georgia, Times">
As a general FYI. Many email clients strip out style sheet information from html based emails. If you have a specific area that you want colored, you may want to consider using images.
That said, you should also be aware that inline styling / excessive use of strong tags which are intended to highlight a CLICK ME link can increase the overall span score of your email message.

Related

Sending image and background image email with php

I am trying to send an email with one image sitting over the top of a background image, I can get it to work if I do this
$message .= "<tr><td background='https://path-to-background/image.jpg'><img src=https://path-to-image/" . $file. " ></td></tr>";
But the background image repeats
If I inline style it it doesnt work at all like this
$message .= "<tr><td><img src=https://path-to-dir/" . $file. " style='background-image: url('https://path-to-background/image.jpg'); background-repeat: no-repeat;'></td></tr>";
I know it may have something to do with " and ' but Ive tried everything and cant get the dam thing to work,
Any help as always is much appreciated
Thanks
Try moving the style property to the <td> tag.
Example:
$message .= "<tr><td background="path to background" style=\"background: url('path to background') no-repeat;\">Content</td></tr>";
Bear in mind that how emails are displayed on different devices will vary. I would recommend using a tool such as litmus to help with getting email templates where you need them.
Please post the entire code, as it may not be only the message body
thats causing problems.
Are you using php mail() or another library?
Did you set your header correctly to show HTML?
You might want to try your HTML code in the browser to make sure it works, before debugging the email (background image repeats sounds like a html/css error?).
Most Email programs do not show HTML correctly. Another argument for testing HTML first. You'll most likely need to inline css, there are a bunch of free tools if you google css inliner, that add the styles as inline.

using PHP tags in href mailto:

I am working in a system that allows for custom system-generated emails to be sent to users.
The system has its own tags (such as [[EMP_NAME]] which outputs the employee's name).
I want to use one of these tags within the body of a <a href="mailto: " link.
However, the tags ( [[EMP_NAME]] ) have their own html tags embedded in them so when it is run, the result of the mailto link displays:
Best regards
<strong>John Smith</strong>
I have tried using <pre > but this just gets included in the mail as well.
I have also tried declaring $strname = <pre>[[EMP_NAME]]</pre> and then including $strname in the link body but with no success.
As this editor is embedded within the software, I'm not sure it's that advanced and I'm probably stretching it as it is - so simplest solution preferred.
Would much appreciate any help with this.
Thanks

how to add background color to html email sent with php mail()

Im trying to add background color to this html email.
Ive tried putting in
<script> tags with css code inside
bgcolor in body tags
and a css style sheet
All of which didnt work.
Ive read that it could possibly be the provider (gmail) I'm sending these tests to, but there has to be a way.
All the ways I have tested on a separate .html file which has all changed to what I wanted. I just cant get it to in the actual email. I am using the mail() in php.
$message = "
<html>
<head>
<title>Rate Your Experience</title>
</head>
<body bgcolor = '#0000FF'>
<center>
<p>
<h2>How well did '$recipient' do?</h2>
<h4>Vacancy Title: '$vac_title'</h4>
<h4>Vacancy ID: '$vac_id'</h4>
</P>
</center>
<center>
<table>
<tr>
<td><h3>we are built on sharing your review with other people who may also want to use this service.</h3></td>
</tr>
<tr>
<td><h3>Please take a minute to reflect on the level of service youve received.</h3></td>
</tr>
<tr>
<td><h3>Your review is public - to other employers registered with Ahoy Employ.</h3></td>
</tr>
<tr>
<td><h3>Should you have any concerns that you would prefer to share in private, please email us at info#website.ca and quote the Vacancy ID shown above.</h3></td>
</tr>
</table>
</center>
</body>
</html>
";
// 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#provider.ca>' . "\r\n";
mail($to,$subject,$message,$headers);
Try Like this:
<body style="background-color:#cfcfcf";>
The first thing to know about email is to throw out everything you know about web standards. Email is still in the 90's. Check out what Litmus and MailChimp are saying.
Use tables for design.
Use tables as containers. Wrap your entire message in a single column, single row table.
Then use the bgcolor of that table to color your email's background.
Forget about using an external style sheet or putting CSS in the head with <style> tags. They get stripped out by various readers. You have to do inline styles in the html tags.
Yes, it defeats the whole purpose of CSS. But like I said, email doesn't follow standards. It's waaaay behind.
If you are using the email template, then you can write inline css as well embedded css in tag.
Other wise you can write the inline css in your html code.
If you are using external css then It will probably not work email at the gmail inbox can not find the path of the css.

Tack a HTML element at the bottom of an existing email body

Here is my use case:
I have integrated my application with SendGrid, and they provide the user a way to customize the unsubscribe link by adding an element with an [UNSUBSCRIBE] in the HTML. Now, there are two reasons why I do not want to edit my existing email templates (HTML files).
There are a lot of them.
I only want to do this in special cases
So, my thought is that I can tack the HTML onto the end of the existing email body in PHP when I go to send out the email, something like:
$html = $html . "<div style='position:absolute;bottom:0px;width:100%;'>"
. "<div style='margin:0px auto;'>"
. "If you would like to stop receiving these emails <a href='[UNSUBSCRIBE]'>click here</a>"
. "</div>"
. "</div>";
But unfortunately, this only places my link at the bottom of the viewable email, not the entire email. So when the user scrolls down, the link is stuck in the middle of the email! I need to place a style on this element, either inline or through CSS, that will place my link all the way at the bottom no matter what. Any ideas?
Make sure its before </body> tag.
Why not to do string replace?
$html = str_replace([yourDIVcode] . '</body>', '</body>', $html);

Email sent by Mandrill has wrong font color

I'm trying to modify the our email message for a forgot-password module.
I'm sending a html content to the json field html and here's the code
<html>
<head>
<title></title>
</head>
<body>
<p>Hello <?= $userName; ?>,</p>
<p>
Someone has requested a link to change your password, and you can do this through the link below.
</p>
<p>
Change my password
</p>
<p>
<?= $webUrl; ?>
</p>
<p>
If you didn't request this, please ignore this email. <br><br>
Your password won't change until you access the link above and create a new one.<br>
</p>
<p>
Best Regards, <br><br>
The Lifebit Team
</p>
</body>
</html>
After a I run the mandrill api, The color of the message is now purple (sometimes most lines are black). Here's the snapshot.
I didn't set any colors in my html code but why is it that some parts are purple? Thoughts?
Thanks ahead!
Sometimes the email client will manipulate the appearance of the email because it is quoted content, or appeared in a previous email.
I know for example, that Gmail will actually hide the content of a previous mail to show you only new content.
In the screen shot, my boss' signature is trimmed because it is not the first message from him in the thread.
Think about it this way, sometimes a browser will "paint" a link in a different color to indicate that it has already been visited (purple for the popular ones). There might be a similar mechanism in the mail client. If for example, you send the same email twice, the second one might appear different as it's content has already been viewed previously.
I assume that the formatting issue is something that is happening on the users email client. There is not much you can do about that other than explicitly defining colors and styles for each message that is sent.
it looks like CSS isn't being inlined for your Mandrill emails. Mandrill doesn't automatically inline CSS styles as MailChimp does, but you can optionally inline your CSS which should resolve the font styling issue you've noticed in Outlook. You can either set it by default for your account on the Sending Options page in your Mandrill account, or enable it on a per-message basis (using the inline_css parameter (API) or X-MC-InlineCSS (SMTP headers)). This will work for HTML under 256KB.

Categories