PHP Email Tutorial: We ever talk how about send email with attachment. Now, in this post, we want to send email where there is images in there as embedded images. Usually, you get this kind of email from newsletter. So, after read this post, you can build your own newsletter.
Before we write line codes, we must understand following anatomy of email that use embedded images:
03 | date_default_timezone_set( 'America/New_York' ); |
05 | $to = "you@miscellaneous4all.blogspot.com" . ", " ; |
06 | $to .= "we@miscellaneous4all.blogspot.com" ; |
09 | $subject = "Test for Embedded Image & Attachement" ; |
12 | $sep = sha1( date ( 'r' , time())); |
16 | "\r\nContent-Type: multipart/mixed; |
17 | boundary=\ "PHP-mixed-{$sep}\"" ; |
20 | $attachment = file_get_contents ( 'attachment.zip' ); |
21 | $encoded = base64_encode ( $attachment ); |
22 | $attached = chunk_split ( $encoded ); |
25 | $headers .= "To: You <you@miscellaneous4all.blogspot.com>, |
26 | We <we@miscellaneous4all.blogspot.com>\r\n"; |
27 | $headers .= "From: Me <me@miscellaneous4all.blogspot.com>\r\n" ; |
28 | $headers .= "Cc: he@miscellaneous4all.blogspot.com\r\n" ; |
29 | $headers .= "Bcc: she@miscellaneous4all.blogspot.com\r\n" ; |
31 | $inline = chunk_split ( base64_encode ( |
32 | file_get_contents ( 'mypicture.gif' ))); |
37 | Content-Type: multipart/alternative; |
38 | boundary= "PHP-alt-{$sep}" |
41 | Content-Type: text/plain |
47 | Content-Type: multipart/related; boundary= "PHP-related-{$sep}" |
50 | Content-Type: text/html |
54 | <title>Test HTML Mail</title> |
57 | <font color= 'red' >Hai, it is me!</font> |
59 | <img src= "cid:PHP-CID-{$sep}" /> |
64 | Content-Type: image/gif |
65 | Content-Transfer-Encoding: base64 |
66 | Content-ID: <PHP-CID-{ $sep }> |
69 | --PHP-related-{ $sep }-- |
74 | Content-Type: application/zip; name= "attachment.zip" |
75 | Content-Transfer-Encoding: base64 |
76 | Content-Disposition: attachment |
84 | mail( $to , $subject , $body , $headers ); |
86 | </me@miscellaneous4all.blogspot.com> |
0 comments:
Post a Comment