Phpmail email with attachment function

Source: Internet
Author: User
$ Subtitle name & quot; testpdf & quot; $ email & quot; test @ testcom & quot; $ text & quot; hello, the attached file contains the PDF file you need. Click to download. & Lt; br & gt; & lt; ahrefhttp: wwwphpfensicom & gt; ww
  1. $ Pipeline name = "testpipeline ";
  2. $ Email = "test@test.com ";
  3. $ Text = "Hello, the attachment contains the PDF file you need. Click to download.
    Www.phpfensi.com "; // text content
  4. $ Text = base64_encode ($ text); // encode it using base64
  5. $ Text = chunk_split ($ text); // cut the long string into 76 characters in each line.
  6. $ Subject = $ subtitle name; // title
  7. $ From = "admin@phpfensi.com"; // sender
  8. $ To = $ email; // recipient
  9. // Attachment
  10. // Define the demarcation line
  11. $ Boundary = "nextpart _". uniqid ("");
  12. $ Boundary2 = "nextpart _". uniqid ("");
  13. $ Headers = "to: $ torn ";
  14. $ Headers. = "from: $ fromrn ";
  15. $ Headers. = "mime-version: 1.0rn ";
  16. $ Headers. = "content-type: multipart/mixed;
  17. Boundary = "---- = _ $ boundary" rn ";
  18. $ Read = file_get_contents ($ External name );
  19. $ Read = base64_encode ($ read); // encode it using base64
  20. $ Read = chunk_split ($ read); // cut the long string into 76 characters in each line.
  21. // Now we can create the subject of the email
  22. $ Body = "this is a multi-part message in mime format.
  23. ------ =_$ Boundary
  24. Content-type: multipart/alternative;
  25. Boundary = "---- = _ $ boundary2 ";
  26. ------ =_$ Boundary2
  27. Content-type: text/html;
  28. Charset = "gbk"
  29. Content-transfer-encoding: base64
  30. $ Text
  31. ------ = _ $ Boundary2 --
  32. ------ =_$ Boundary
  33. Content-type: application/octet-stream;
  34. Charset = "gbk ";
  35. Name = "$ Your name"
  36. Content-disposition: attachment; filename = "$ parameter name"
  37. Content-transfer-encoding: base64
  38. $ Read
  39. ------- = _ $ Boundary --";
  40. If (mail ($ to, $ subject, $ body, $ headers ))
  41. Echo "the PDF file (". $ your name. ") you need has been sent to your email:". $ .".
    Check. ";
  42. Else
  43. Echo "Sorry, failed to send.
    ";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.