php image display without download in mail - php

hi i want to send a image in html format using php mailer class but image show in mail after downloading. but i want to display the image without downloading. is there any option in mailer class or there is another method for this.
or i have to send the the image in another format.

Well, there can be only two possible answers:
you do not want to embed the actual image file with the eMail, then simply put an <img> element into the eMail linking to the image at the remote location, just like you would with any other HTML page. Then cross fingers and hope the client has HTML email enabled and allows display of remote images.
or
you dont want to reference the file from a remote server, but embed it with the eMail. In that case, refer to How To Embed Images in HTML EMail or Attaching an image to an email

If your using PHP Mailer...
$mail = new PHPMailer();
$mail->SetFrom("blah#blah.com");
$mail->AddAddress("blah#blah.com");
$mail->Subject = "Blah"
$mail->MsgHTML('<html><body><img src="logo.jpg">Hello</body></html>');
$mail->AddAttachment("logo.jpg");
$mail->Send();
Using AddAttachment PHP Mailer will check your HTML for a reference to that file and automatically embed it for you.

buddy, its really simple. Write html code as if you write in developing a web page. Give the complete url to the image in the src attribute.
Dont forget to user the function eregi_replace() on body html
$html_message = eregi_replace("[\]",'',$body_html_string);
engoy !!!!! ;)

Related

How insert image in a email without call url and without use attachment?

Looking for html-email format, how i can include a jpeg-image (logo) in a email without call absolute address from website and without put it as attachment in it?
Thanks.
Basically you need to read the contents of the image and transfer them to data uri which you can "inline" into the html like this:
$image_data=file_get_contents("some_image.jpg");
$encoded=base64_encode($image_data);
echo "<img src='data:image/jpeg;base64,{$encoded}'>";
Of course you will not echo the image tag, you just ineed to put it into the email with your preferred mailer client.

Phpmailer add PDF attachment from a link

I'm using PHPMailer to send automatic email (obviously using PHP as programming language).
I would like to add a PDF attachment generated with TCPdf.
Unfortunately I cannot generate the PDF inside the php page where I'm using PHPMailer, and I cannot create a function that generate it.
I can only use a link to generate it, like this:
www.mypage.com/app-pdf/link_generate_pdf.php?IDToGenerate=131&PDFOutput=I
I was thinking that I can recall the page with the PDFOutput=S and "return" in some way the text of the PDF and add it as attachment.
Otherwise I can call the page with PDFOutput=F and save it to a temp folder and then attach it to the email.
The problem is that I don't know how to "call" a page as it were a function and return what the recalling page actually returns.
Do you have some suggestion?
Thank you
edit: I now understand the problem! The problem is that the URL is accessible only from autentication (login page). I thought that as I was logged in, the script was automatically capable of read the page. How can I solve this?
Use this to save the file on the server first and then attach
file_put_contents("Tmpfile.pdf", fopen("http://example.com/file.pdf", 'r'));
Attach as
$mail->AddAttachment('path_to_pdf/Tmpfile.pdf', $name = 'Name_of_pdf_file',
$encoding = 'base64', $type = 'application/pdf');
Hope this helps
Edit: Try this. works fine over here
file_put_contents("path_to_pdf/Tmpfile.pdf",
file_get_contents("http://example.com/file.pdf"));

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!

disable opening pdf in browser php

I am using FPDF plugin. I want to send email with pdf file. Everything is working fine. But, the problem is, after sending email my browser still shows the pdf file because of the content type header. Is there any way to disable that thing in certain condition?
Thanks.
If you use $pdfContent = $pdf->Output('', 'S'); there shouldn't be any content send. See here for more details.

How do I embed images in HTML email? [duplicate]

This question already has answers here:
How to embed images in email
(6 answers)
Closed 9 years ago.
Duplicates:
How to embed images in email
How to embed images in html email
Embed images for use in email message using PHP?
I am sending HTML emails using php. I want to use embedded images in the HTML. Is it possible? I have tried lot of different methods, but none are working. Is anyone able to help me please?
Thanks
You need to provide the whole url where your image resides
example:
<img src='http://www.mydomain.com/imagefolder/image.jpg' alt='my-image' width='' height=''>
This isn't really trivial, but with a couple of tries doable.
First of all, learn how to build a multipart email, that has the correct images attached to it. If you can't attach the images, they obviously won't be in the email. Make sure to set the type to multipart/related.
Secondly, find out how to set the cid references, in particular the Content-ID header of the attachment.
Third, glue it all together.
At each step, do the following:
look at the result
send the email to yourself, and compare it to what you received
compare it to a working example email
I find the best way to send images via email is to encode them with base64.
There are loads of links and tutorials on this but here is this code for Codeigniter should suffice:
/* Load email library and file helper */
$this->load->library('email');
$this->load->helper('file');
$this->email->from('whoever#example.com', 'Who Ever'); // Who the email is from
$this->email->to('youremailhere#example.com'); // Who the email is to
$image = "path/to/image"; // image path
$fileExt = get_mime_by_extension($image); // <- what the file helper is used for (to get the mime type)
$this->email->message('<img src="data:'.$fileExt.';base64,'.base64_encode(file_get_contents($image)).'" alt="Test Image" />'); // Get the content of the file, and base64 encode it
if( ! $this->email->send()) {
// Error message here
} else {
// Message sent
}
Here is a way to get a string variable without having to worry about the coding.
If you have Mozilla Thunderbird, you can use it to fetch the html image code for you.
I wrote a little tutorial here, complete with a screenshot (it's for powershell, but that doesn't matter for this):
powershell email with html picture showing red x
And again:
How to embed images in email

Categories