php - How to embed images in html email -


I am trying to implement a code to send HTML emails with an embedded image.

I tried the simple HTML email with the image already, but this image was taken from the server.

I like sending a library email
It's easy and handles most problems for you automatically.

Regarding displaying embedded (inline) images, here's what:

inline attachments

An additional way to add an attachment is. If you want to create an HTML e-mail with images included in the desk, then it is necessary to attach the image and then link the tag to it. For example, if you add an image as an inline attachment with the CID Mary-photo, then you can call it within the e-mail & lt; Img src = "cid: my-photo" alt = "can be accessed with my-photo" /> Gt; .

In detail, here is the task of adding an inline attachment:

  $ mail-> AddEmbeddedImage (filename, cid, name); // With the value of this example using this function, result in this code: $ mail-> AddEmbeddedImage ('my-photo.jpg', 'my-photo', 'my-photo.jpg');  

Give you a more complete example of how it will work:

  & lt ;? Php require_once ('../ class.phpmailer .php'); $ Mail = new PHPMailer (true); // REAL Ultimate means that it will throw exceptions on errors, which will require us to catch $ Mail- & gt; IsSMTP (); // Try trying to use the SMTP client {$ mail- & gt; Host = "mail.aramedom.com"; // SMTP server $ Mail- & gt; Port = 25; // Set the SMTP port $ mail-> Setfrum ('name@yourdomain.com', 'First Last'); $ Mail- & gt; AddAddress ('whoto@otherdomain.com', 'John Do'); $ Mail- & gt; Subject = 'PHPMailer Test'; $ Mail- & gt; AdMbeded Image ("Rocks Page", "Mary-Attach", "Rocks Page"); $ Mail- & gt; Body = 'Your & lt; B & gt; Html & lt; / B & gt; With an embedded image: & lt; Img src = "cid: my-attach" & gt; Here's an image! '; $ Mail & gt; AddAttachment ('something.zip'); // This is a regular attachment (not inline) $ Mail- & gt; Send (); Echo "message has been sent ; p & gt; & lt; / p & gt; \ n"; } Hold (phpmailerException $ e) {echo $ e- & gt; Error message (); // Pretty error message from PHPMailer} Hold (exception $ e) {ebay $ e- & gt; GetMessage (); // Boring error message from something else! }? & Gt; Edit  

:

Regarding your comment, you asked how to send HTML Email with images embedded, so I To give you an example to do this. I told you about the library that you can send emails using many methods besides SMTP.
Take a look at other examples.

The only way or the other, if you do not want to send email to the library in ways that are supported, you can use the library to create the message (anyway), then the way you You can send it to you.

For example:

You can take the place of the email that sends the email:

  $ mail-> Send ();  

with:

  $ mime_message = $ mail-> CreateBody (); // retrieve message contents $ mime_message echo; // Echo it on screen or send it using the desired method  

Hope it helps me tell me if you are having trouble using it.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -