After learn send email with dual format (HTML/text), we will learn how to send email with attachment. In this situation, we will make the primary MIME type be multipart/mixed so that we can do an attachment or two.
03 | date_default_timezone_set('America/New_York'); |
05 | $to = "you@miscellaneous4all.com" . ", " ; |
06 | $to .= "we@miscellaneous4all.com"; |
09 | $subject = "Test for Attachement"; |
12 | $sep = sha1(date('r', time())); |
17 | "\r\nContent-Type: multipart/alternative; |
18 | boundary=\"PHP-alt-{$sep}\""; |
21 | $attachment = file_get_contents('attachment.zip'); |
22 | $encoded = base64_encode($attachment); |
23 | $attached = chunk_split($encoded); |
26 | $headers .= "To: You <you@miscellaneous4all.com>, |
27 | We <we@miscellaneous4all.com>\r\n"; |
28 | $headers .= "From: Me <me@miscellaneous4all.com>\r\n"; |
29 | $headers .= "Cc: he@miscellaneous4all.com\r\n"; |
30 | $headers .= "Bcc: she@miscellaneous4all.com\r\n"; |
35 | Content-Type: text/plain |
40 | Content-Type: text/html |
44 | <title>Test HTML Mail</title> |
47 | <font color='red'>Hai, it is me!</font> |
54 | Content-Type: application/zip; name="attachment.zip" |
55 | Content-Transfer-Encoding: base64 |
56 | Content-Disposition: attachment |
64 | mail($to, $subject, $body, $headers); |
66 | </me@miscellaneous4all.com> |
0 comments:
Post a Comment