Skip to content
  • Home
  • Server-Side
    • php
    • Node.js
    • ASP.NET
    • Magento
    • Codeigniter
    • Laravel
    • Yii
    • CRUD
      • CRUD Database Application
      • CRUD operation in Client side
      • CRUD operation with server side
  • JavaScript
    • AngularJS
    • Ajax
    • VueJs
    • jQuery
    • ReactJS
    • JavaScript
    • SEO
  • Programming
    • Android
    • C programming
    • CSS
    • Mysql
    • Mysqli
  • Technology
    • Software
      • webinar software
      • webinar conferencing software
      • soundproof
    • Adsense
      • Google
      • Earn Money
      • Google Adsense
        • Adsense fraud
        • Adsense Secrets
        • Adsense software
        • Adwords advice
        • Adwords strategy
        • Google adwords help
        • How to get google ads
    • Tips and Tricks
    • Interview
    • Insurance
    • Religious
    • Entertainment
      • Bollywood
      • tamilrockers
      • Hollywood
  • Health Care
    • LifeStyle
    • Women
    • Fashion
    • Top10
    • Jobs
  • Tools
    • Screen Resolution
    • WORD COUNTER
    • Online Text Case Converter
    • what is my screen resolution?
  • Guest Post
    • 4cgandhi
    • IFSC Code

PHP Multiple Email Attachments with Sending Email AJAX Multiple File upload

June 22, 2018June 22, 2018 by Pakainfo

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.

Read Also:  How to delete or clear caching in Laravel?

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.

Read Also:  PHP Contact Form Send Email File Attachment Example

//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

<?php
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"; 

    // 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>";

?>

Example

Read Also:  Display tosql or Raw SQL query from Query Builder in Laravel

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  PHP Mail Attachment - Php Send Email File-Images Attachments
  2. Read Also:  Laravel 5.7 Routing Required Parameter
  3. Read Also:  PHP SEND mail with Multiple Attachments
  4. Read Also:  PHP Secure Session Management System
  5. Read Also:  Insert update delete Using Laravel 5.2 Ajax CRUD laravel without refresh page
  6. Read Also:  Laravel Insert Update Delete Multiple checkbox value Example
  7. Read Also:  PHP Send HTML Email File Attachment Using PHPs mail
  8. Read Also:  Data auto Load While scrolling page down with jquery PHP and MySQL
  9. Read Also:  How to Make Async Requests in PHP
  10. Read Also:  Laravel Blade check if variable is empty/isset
Categories Mysql, Mysqli, Programming Tags email with multiple attachments (html5 php) download, multiple file attachment in php in email, php code to send email with attachment, php form with multiple attachments, php send html email with multiple attachments, phpmailer multiple attachment example, send multiple attachment in email using php, write a program in php to send an email along with attachment
Post navigation
PHP Facebook Graph API GET comments hide-delete comments
paypal payment Gateway Integration with laravel 5.5 -Paypal checkout Laravel

Categories

Ajax (418) AngularJS (357) ASP.NET (61) Bollywood (35) Business (16) Codeigniter (141) C programming (13) CSS (62) Earn Money (50) Education (30) Entertainment (41) Events (14) Google Adsense (58) Government (13) Highcharts (77) Hollywood (34) Interview (18) JavaScript (864) Jobs (25) jQuery (941) Laravel (1008) LifeStyle (31) linux (18) Misc (13) Mysql (871) Mysqli (779) Node.js (34) php (1686) Programming (2179) Python (44) ReactJS (33) SEO (22) Software (16) Software (38) tamilrockers (30) Tech (15) Technology (2187) Tips and Tricks (75) Tools (27) Top10 (109) VueJs (249) Web Technology (28) wordpress (135) World (22) Yii (14)
© 2021 Pakainfo • Developed By Pakainfo.com