How To Send Mail with Attachment in PHP
I this tutorial,I will explain how to send mail with attachments in PHP.
you can send attachments using a multipart/mixed content header.then convert the attachment into a base64 string.We are  creating a very simple script with php.
the script sends an email to that address with a pdf file(attached file)that I specify in the script.

Here's a simple php example of sending html mail with attached file:

ExampleHow To Send Mail with Attachment in PHP
$file_path="files/test.pdf";//// Path to the file 
$file_path_type = "application/pdf"; 
$subject = "Testing File attachment"; 

$headers = "From: ".$from. "\r\n" .
$from =""; //From email.
$message = "Hello!!<br>";
$to =""; //To email

$file = fopen($file_path,'rb');
$data = fread($file,filesize($file_path));
$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message .= "\n\n";

//convert the attachment into a base64 string
$data = chunk_split(base64_encode($data));

$message .= "--{$mime_boundary}\n" .
"Content-Type: {$file_path_type};\n" .
" name=\"{$file_path_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .

$sent = @mail($to, $subject, $message, $headers);

if($sent) {
echo "Sent Succesfully";

} else {
die("Email not Delivered");


I hope this will help you to send email with attachments in PHP.