Sending image and background image email with php - 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.

Related

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

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);

PHP display a generated image in mail

So when users sign up, they get an email, and I'm trying to add an image to that email. That image is dynamically generated using php, so its not a static url. The code works, but when I add it to the email code, the image shows up blank. I know the code works because I have echo'd the body, and the image showed up fine in my browser but empty in the email (i have a border around the image, the border shows up, inside is empty).
$img = "<img src='../inc/barcode.php?id=".$regid."' style='padding:5px; border:2px dashed '/>";
elsewhere
$body .= $img;
So does anyone know why the image won't display, and how I could make it so it does?
Also, another question to kind of go off this, how do I display a generic url for the image so that instead of /img.php?id="" it just reads /img.php or something.
You are using relative links, not absolute.
$img = '<img src="http://www.mydomain.com/inc/barcode.php?id='.$regid.'" style="padding:5px; border:2px dashed" />';

gmail is not displaying html text properly

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.

Drupal imagecache is not working for the first time

i am using image cache for my banner image in newsletter.Am uploading and sending the image to mail. The problem is that the image is not loading for the first time. If i again come and edit the page it will send a mail with proper image
$output = "
<html>
<body>";
$output.= theme( 'imagecache', 'banner_img', 'images/motel_wright-1.1.png', 'Wright Motel', 'Wright Motel' );
$output.= "
</body>
</html>";
print $output;
Please help me
I have had similar problems. Few suggestions:
1) As you are using the theme function you might need to rebuild the registry. Try
http://api.drupal.org/api/drupal/includes!theme.inc/function/drupal_theme_rebuild/7
2) If the above fails you will need to use xdebug and find out which function in drupal was not triggered in the first place.
Do post your finding here.

Categories