Attach File Through PHP Mail

前端 未结 1 959
走了就别回头了
走了就别回头了 2021-01-25 23:33

I am trying to get a custom contact form using PHP mail to have a user attach a photo, that then gets sent to the recipient outlined in the PHP mail code



        
相关标签:
1条回答
  • 2021-01-25 23:51

    That is not how attachment works. Using the mail() for attachments is a little more complex than that. You got to tell mail() which part should handle the file attachment and which part is responsible to display the email body by setting up a MIME Boundary. In other words, the code should be divided into 2 parts:

    • A section to handle the message being sent in body
    • A section to handle file uploading

    A detailed tutorial is here

    PHP EMAIL WITH ATTACHMENT

    However, I would suggest you to use a very handy tool called PHPMailer to do the same task. It simplifies the process and lets the class handle all the legwork.

    PHPMailer

    0 讨论(0)
提交回复
热议问题