Learn how to a build a cloud-first strategyRegister Now


image opening by default

Posted on 2012-08-23
Medium Priority
Last Modified: 2012-08-29
Content-Transfer-Encoding: base64
Content-Disposition: inline;
Content-Type: image/png;

I received an email where in gmail and other clients (I never set the preferences to allow this email address pictures), the picture was opened by default

is this something I can do in php mail()
or another php mailing library (swiftmailer, phpmailer())
Question by:rgb192
LVL 35

Accepted Solution

gr8gonzo earned 2000 total points
ID: 38328830
Hi rgb192,

If a picture is displayed without prompting you to open it, that means that the image contents are actually contained inside the email.

So if your email body is "Hi! Here is a picture of me! <img src='http://www.somewhere.com/me.jpg'>" then you would end up with a less-than-1k email message with an image that requires the reader to specifically accept/allow the image to be shown, because it is hosted somewhere else and that can be dangerous to open something remotely.

However, with an embedded image, your email body looks like "Hi! Here is a picture of me! <img src='cid:picofme'>" and then in another part of the message (because this requires a MIME-encoded multi-part message, meaning that there are different "sections" of the message), the image is attached like a regular attachment but given the Content-ID of "<picofme>"

You can do this easily with PHPMailer:

$mail->AddEmbeddedImage("photoofme.jpg", "picofme", "photoofme.jpg");
$mail->Body = 'Hi! Here is a picture of me: <img src="cid:picofme">';

Just be warned - this also means that your emails could be much larger, since they contain encoded images (which are usually about 30% bigger in file size than the original source image). Also, not ALL email readers will automatically open embedded images. It will have a higher likelihood than linked, remote images, but there are many that will still prompt you to display them, because there have been vulnerabilities discovered in certain images, so it is still a security issue.

Overall, it's usually better not to embed images but use the linked versions instead. People who want to see your images in your email are going to load the images, while people you don't want to see the images will not need to load them. This means that you have saved a lot of bandwidth by only delivering images to the people who want them, while still giving the recipients what they want and making it fast to download the emails.

Author Closing Comment

ID: 38347927

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question