PHPmailer's AddEmbeddedImage method not working - php

I'm trying to test the PHPmailer class to embed image (http://www.google.gr/intl/en_com/images/srpr/logo1w.png) inside an e-mail
I'm using this code (along with standard one, that 100% works, mail is delivered):
$mail->AddEmbeddedImage($src, 'test', basename($src));
and this is placed the e-mail body:
<img src="cid:test">
Image is not showing up. What may I doing wrong?

Taken from some piece of the documentation:
$path is the path of the filename. It can be a relative one (from your
script, not the PHPMailer class) or a full path to the file you want
to attach.
Have you tried using a local image?

cid:test isn't valid url for image.

Related

PhpMailer not embedding image in mail body but attaching

I am sending email using PHPmailer and tying to embed image in mail body (using CID method <img src="cid:qrcode" />) but it always attaching image instead of embedding.Can anyone tell me what's wrong with my code (commented lines in code, already tried. ).
Here is the screenshot of my code
First of all you're using a very old version of PHPMailer, and have based your code on a very old example. Get the latest.
The other obvious problem is that while you're putting HTML into Body, you've commented out the call to isHTML(), so your message is being sent as plain text, which has no concept of displaying images inline. Uncomment this line:
$mail->isHTML();
Also bear in mind that in MIME there is essentially no difference between attachments and inline images - everything is an attachment, it's just that some attachments may be referred to from HTML parts, and HTML-capable clients can make use of that linkage.
If Outlook is removing src attributes, that's clearly not your sending code's problem. Outlook does some very unpleasant things to email.
One other minor thing: instead of dirname(__FILE__) you can use __DIR__ in any current version of PHP.
just as an assistance I encountered the same problem and after much mumbling arrived at a solution which might help others.
Tried dumping the image in the same folder - nope
Tried DIR variable to dynamicalyly pull in the image - nope
Finally, hardcoded the path to the folder in which my embedded image lived, hurrah
Magic forumla for me (using PHPmailer v5.5) - note I'm using Plesk so your definitive path may differ, use mine as a guide...
$mail->AddEmbeddedImage("/var/www/vhosts/{domainname}/httpdocs/{foldername)/image.jpg", "emailimg", "image.jpg");
I note that when calling in the image as an embedded image that i had to use the same filename as I think PHPmailer uses the structure:
embedded-img-name source, reference id, embedded-img-name within the internal AddEmbeddedImage call
Hope it helps someone!
Try this code i think it will work for you
$mail->AddEmbeddedImage('img/2u_cs_mini.jpg', 'logo_2u');
and on the tag put src='cid:logo_2u'

png attachment generated by an API in phpmailer

I'm trying to send a .png image to my user via phpmailer. The image is shown when I use <img> tags, but I want it to display as a real attachment that the user can open/save/print (like in this screenshot). I read that I can use $mail->addStringAttachment for this. So I tried this, and it does send an attachment with the email, but when I try to open it, it says that Windows Picture Viewer can't open the file. Also saving to my computer and then opening with Paint doesn't work, it tells me thats not a valid file or something. I think this is because it's no static image, but an image generated by an API, namely:
$qr = 'http://api.qrserver.com/v1/create-qr-code/?data=' . $guid . '&size=250x250';
So this image should be sent as an attachment. Does anyone know how I can make this work?
I got it to work fine as an attachment by doing the following:
$qr = file_get_contents("https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Example");
$mail->addStringAttachment($qr, "qr.png");
The reason it's failing is that you're trying to attach the URL as image data. You need to fetch the data from the URL first, then attach it to something.
Go one step at a time - make sure that you're getting back valid image before trying to email it - e.g.
file_put_contents('qr.png', file_get_contents($qr));
and make sure you get a valid image saved in there. When you know that's working, then try and email it with
$mail->addStringAttachment(file_get_contents($qr) 'qr.png');
Though perhaps with a bit more error checking!

Unsupported image type with fpdf

i have this message error:
Unsupported image type:imagePath was not found on this server.
I want to create pdf with jpg images taken from the iphone. Unfortunately this does not work. The image path is just seen that I can access it from my browser. When I change the way the path is erroneous.
A exemple of the code
$pdf->Image('../firstParthPath/'.$_SESSION['environment'].'/secondParthPath'.$ImageName,null,$heigth,40,50);
$ImageName are /image404-120404.jpg for exemple. I have tested variable name. It has /image404-120404.jpg
$heigth is a variable that is also handled automatically. It always has the desired content.
I tried to replace null with 0
I tried to add the option 'JPG'. Without success.
a exemple of image
http://imageshack.us/photo/my-images/72/image398120404.jpg/
It could be that PHP is not understanding the location via the relative path starting with '../'. You could try explicitly prepending the script path before it to make sure PHP is looking in the correct place:
(dirname(__FILE__) . '/../firstParthPath/'.$_SESSION['environment'].'/secondParthPath'.$ImageName,null,$heigth,40,50);
It's resolved. It was a verification error in the next picture. Now the problem's are resolved

help with inline images/mail with cron - php?

I've got mailings that need to be sended using cron. When I load the script manualy all works fine. With cron i get broken images.
to change the src of my img i used:
$body = eregi_replace("managersrc_logo","images/managers/acertainlogo.jpg",$body);
Because i thaught that it is importent to use absolute paths i also tried:
$body = eregi_replace("managersrc_logo","http://www.site.com/images/managers/acertainlogo.jpg",$body);
In that case i even do not see the images when i run the cronscript manualy. Nor the automated cron will display me the images.
When i check the source of the mail that is received i always see "cid:encryptedstuff" even if i use absolute paths? Why is that? I just want my absolute paths being printed in the src attribute of the img tag. Who changes my absolute path to cid: ? is it php, phpmailer or outlook itself?
Any help someone?
can you post a sample html before and after being replaced (but before being sent)? maybe it has additional characters that break the url, ie src="/managersrc_logo". Also, maybe your mailing program has an option to integrate the images inside the message and can't find them?
The problem was an older version of phpmailer. I updated to the new version and the images are displayed perfectly now!!

how can I assign a variable to hold an image in php

I was just wondering if I could have a variable to hold an image, I'm using phpmailer to send email and I need an image to be attached to it,
so I was wondering if I could put the image in a variable and use
$mailer->AddAttachment($image);
to send the email with attachment.
thanks for your help.
With PhpMailer adding an attachment is done the way you wrote it in the question
$mailer->AddAttachment('/home/mywebsite/file.jpg', 'file.jpg');
If you want to use a variable you can change the string by a variable without problem.
$imagePath = '/home/mywebsite/file.jpg';
imageName = 'file.jpg'
$mailer->AddAttachment($imagePath, $imageName);
I guess $image should contain local path to the image file.
If you look at phpMailer source, at line 1218:
http://phpmailer.svn.sourceforge.net/viewvc/phpmailer/phpmailer/trunk/class.phpmailer.php?revision=444&view=markup
you'll see that it verifies at first that what you have given is path to existing file. There is no other option.
Unless I'm missing something, that's exactly how it's supposed to be used.
According to this document, you'd do something like this:
$myImg = '/some/path/to/image.jpg';
$mailer->AddAttachment($myImg);
Is that not what you're trying?
Why cant you do this this way? Sending email attachments in PHP Using phpmailer class !

Categories