Send Email with Attachment in PHP, Send Attachment in Email in PHP

Send Email Attachment in PHP

Hello friends today i am going to provide a tutorial regarding how to send email attachment in PHP. For a normal mail sending you can visit my previous article in which you will learn how to send mail in php how to send email in php In this tutorial you will get the whole code and its really a very short code to send the attachment. Sending an email attachment in php is not an easy task many time you will get the errors like file is of 0 kb, file name is something else, email is delivered but no you dont get the mail etc. In this tutorial / Example you will get he procedure of how to send the email attachment in php.

Demo Link

Things we need to send email attachment in php

  • HTML Form
  • PHP Code

Email sending HTML Form

First we will start with the html for. In html form we will use the these text fields

  • To – On which mail is delivered
  • Message – Message which is to be delivered
  • Subject – Subject for the Email
  • Attachment – Email attachment which you want to send

Below is the HTML code for email sending

Now we have finished with our html form. Lets move to our PHP code

Email attachment php code

Here will write the PHP code for the attachment sending with the help of php.

First we will receive our data and retain that data below is the code

Now we will send the email with attachment in php

From the above demo you can check this or click the below link to check it on separate page. Below is the working code you can download it also.

1.1 KiB


  1. I am using windows sir, I am also getting the same problem

  2. I actually have the same problem with the other commenters, I used your code but there was no mail.

  3. bhuvaneswari.s

    November 5, 2015 at 08:19

    haaii,.. its not working.. i got a success mail message.. bt i could not get any mail.

  4. Hi, Vivek.. i’m also using this code. mail sent message displayed , but i dont have received any other mail and attachements. pls help me.. thanks in advance…

  5. vivek sir thanx for provide the code……………………….
    but i a have problem …
    the file attach properly but it size 0 bite…….
    plz help me…………. i m wait your replay

  6. Thank you so much for this tutorial.
    I have use your code, it sent attachments successfully, but there message body is empty.
    Can you please help me for this problem.
    I am testing it on Linux hosting.
    Please help me for this.
    Thanks in advance.

  7. thanks bro…. thank you very much…. your are the best

  8. Hi Vivek Sir,


  9. Your The Best Dude..ThankYou

  10. ehen i run you demo it works .. even i got email with attachment .. but when i apply this code in my file .. no mail .. 🙁

Leave a Reply

Your email address will not be published.