PHP Multiple Email Attachments with Sending Email AJAX Multiple File upload
In this Post We Will Explain About is PHP Multiple Email Attachments with Sending Email AJAX Multiple File upload With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to attachment – How to attach two or multiple files and send mail in PHPExample
In this post we will show you Best way to implement php scripts: Send an Email with Multiple Attachments in PHP, hear for Send Email multiple file attachment using PHPwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
At first we will make a simple function named simple_multiple_send_email_attach(). This simple function required some arguments with parameters, like as areceiver email, email email_subject, email send_msgbody, sender email, sender name and simple attachment multiple_files array. Please watch the source following code given below the comment lines for better simple or easy way to understanding.
function simple_multiple_send_email_attach($to, $email_subject, $send_msgbody, $mail_sender, $mail_sendername, $multiple_files){ $from = $mail_sendername." <".$mail_sender.">"; $simple_headers = "From: $from"; //Devloped by : live24u . com boundary $semi_rand = md5(time()); $tye_mime_boundry = "==Multipart_Boundary_x{$semi_rand}x"; //Devloped by : live24u . com simple_headers for attachment $simple_headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$tye_mime_boundry}\""; //Devloped by : live24u . com multipart boundary $send_msgbody = "--{$tye_mime_boundry}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $send_msgbody . "\n\n"; //Devloped by : live24u . com preparing attachments if(count($multiple_files) > 0){ for($i=0;$i<count($multiple_files);$i++){ if(is_file($multiple_files[$i])){ $send_msgbody .= "--{$tye_mime_boundry}\n"; $fp = @fopen($multiple_files[$i],"rb"); $param = @fread($fp,multiple_filesize($multiple_files[$i])); @fclose($fp); $param = chunk_split(base64_encode($param)); $send_msgbody .= "Content-Type: application/octet-stream; name=\"".basename($multiple_files[$i])."\"\n" . "Content-Description: ".basename($multiple_files[$i])."\n" . "Content-Disposition: attachment;\n" . " filename=\"".basename($multiple_files[$i])."\"; size=".multiple_filesize($multiple_files[$i]).";\n" . "Content-Transfer-Encoding: base64\n\n" . $param . "\n\n"; } } } $send_msgbody .= "--{$tye_mime_boundry}--"; $returnpath = "-f" . $mail_sender; //send email $mail = @mail($to, $email_subject, $send_msgbody, $simple_headers, $returnpath); //function return true, if email sent, otherwise return fasle if($mail){ return TRUE; } else { return FALSE; } }
Use the Function and Send Email:
Declare some parameterss, like receiver email, email email_subject, email send_msgbody, sender email, and sender name. $to parameters is need for simple holda data the get receiver mail_id, $from parameters is need for simple holda data the sender email id, $from_name parameters is need for simple holda data the sender name, $attachment_multiple_files parameters is need for simple holda data the attachment multiple_files path array, $email_subject parameters is need for simple holda data the email email_subject, $html_content parameters is need for simple holda data the email body content.
WE only need to change two parameterss value. Firstly change the $to parameters value with the get receiver mail_id and and then change the $attachment_multiple_files value with the attachment multiple_files path array. and then call the as well as created simple PHP function and pass the parameterss as the simple PHP function arguments. Please see the following source code given below and below the comment line.
//Devloped by : live24u . com email parameterss $to = 'get receiver mail_id'; $from = '[email protected]'; $from_name = 'live24u'; //Devloped by : live24u . com attachment multiple_files path array $multiple_files = array('screencapture-www-live24u-in.png','Send_Email_with_pdf_attachment_in_PHP.docx'); $email_subject = 'PHP Email with multiple attachments by live24u'; $html_content = '<h2>PHP Email with multiple attachments by live24u</h2> <p><b>Total Attachments : </b>'.count($multiple_files).' attachments</p>'; //Devloped by : live24u . com call simple_multiple_send_email_attach() function and pass the required arguments $send_email = simple_multiple_send_email_attach($to,$email_subject,$html_content,$from,$from_name,$multiple_files); //Devloped by : live24u . com print send_msgbody after email sent echo $send_email?"<h2> Mail Sent</h2>":"<h2> Mail not SEND</h2>
Full Source code
"; $simple_headers = "From: $from"; //Devloped by : live24u . com boundary $semi_rand = md5(time()); $tye_mime_boundry = "==Multipart_Boundary_x{$semi_rand}x"; //Devloped by : live24u . com simple_headers for attachment $simple_headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$tye_mime_boundry}\""; //Devloped by : live24u . com multipart boundary $send_msgbody = "--{$tye_mime_boundry}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $send_msgbody . "\n\n"; // preparing attachments if(count($multiple_files) > 0){ for($i=0;$i<count($multiple_files);$i++){ if(is_file($multiple_files[$i])){ $send_msgbody .= "--{$tye_mime_boundry}\n"; $fp = @fopen($multiple_files[$i],"rb"); $param = @fread($fp,multiple_filesize($multiple_files[$i])); @fclose($fp); $param = chunk_split(base64_encode($param)); $send_msgbody .= "Content-Type: application/octet-stream; name=\"".basename($multiple_files[$i])."\"\n" . "Content-Description: ".basename($multiple_files[$i])."\n" . "Content-Disposition: attachment;\n" . " filename=\"".basename($multiple_files[$i])."\"; size=".multiple_filesize($multiple_files[$i]).";\n" . "Content-Transfer-Encoding: base64\n\n" . $param . "\n\n"; } } } $send_msgbody .= "--{$tye_mime_boundry}--"; $returnpath = "-f" . $mail_sender; //Devloped by : live24u . com send email $mail = @mail($to, $email_subject, $send_msgbody, $simple_headers, $returnpath); //Devloped by : live24u . com function return true, as well as if email sent, otherwise return fasle if($mail){ return TRUE; } else { return FALSE; } } //Devloped by : live24u . comemail parameterss $to = 'get receiver mail_id'; $from = '[email protected]'; $from_name = 'live24u'; //Devloped by : live24u . comattachment multiple_files path array $multiple_files = array('screencapture-www-live24u-in.png','Send_Email_with_pdf_attachment_in_PHP.docx'); $email_subject = 'PHP Email with multiple attachments by live24u'; $html_content = '<h2>PHP Email with multiple attachments by live24u</h2> <p><b><Total Attachments : </b>'.count($multiple_files).' attachments</p>'; //Devloped by : live24u . comcall simple_multiple_send_email_attach() function and pass the required arguments $send_email = simple_multiple_send_email_attach($to,$email_subject,$html_content,$from,$from_name,$multiple_files); //Devloped by : live24u . com print send_msgbody after email sent echo $send_email?"<h2> Mail Sent</h2>":"<h2> Mail not SEND</h2>"; ?>
I hope you have Got What is Sending email with multiple attachments with PHP And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.