how to send an HTML email with an inline attached image with PHP -
I have a PHP script that sends an HTML email with an attached image. It works extremely well, however, in the email body, I I think the important part is that I am doing wrong here, because it creates a separate attachment instead of an inline attachment that I can use: I tried to change it to use CID but I do not know how to do it , And this 'absolutely not work': Here's the full code: (This is based on a comment on PHP First, the boundary string is created, and the image, correctly encoded and selected: In the HTML section of the email, the image is referred to this way (using the boundary string): Then you make another part of the email under the HTML section for the inline attachment, such as: ... and that's it! Easy to implement PHPmailer or any other libraries, if it's all you are doing, no doubt for more complex tasks, you would like to get one of those libraries. & lt; Img & gt; Attachment can not be found to display in the tag Attached file is called
postcard.png and the original file name on the server is
4e60348f83f2f.png . I have tried to give the image as different things:
cid: postcard.png ,
cid: 4e60348f83f2f.png ,
postcard.png , And
4e60348f83f2f.png . nothing works.
< Code> Content-Transfer-Encoding: Base64 Content-Dispute: Attachment; Filename = "$ fname" // i.e.: "postcard.png"
Content-Transfer-Encoding: base64 Content-ID: & lt; $ Fname & gt; // Eye: postcard.
Mail page.)
& lt ;; Php $ to = "recipient@email.com"; $ Email = "sender@email.com"; $ Name = "name"; $ Theme = "an inline image!"; $ Comment = "Lookout at Lt. Beed"; Lille
mail was not sent! "; ? & Gt; I got the answer in the end, which has become remarkably simple. That helps me understand it, but I will display those parts that I needed to lower it.
// Create a border string. This requires unique (not in the text) ... // We are going to use sha1 algorithms to generate a 40 character string: $ sep = sha1 (date ('r', time ()); // Still prepare our inline image - Read, encode, split: $ inline = chunk_split (base64_encode (file_get_contents ('figure.gif')));
- PHP-related - {$ sep} Content-Type: Image / GIF Content-Transfer-Encoding: base64 Content-ID: & lt; PHP-CID - {$ sep} & gt; {$ Inline}
Comments
Post a Comment