Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
    • Guest Posting Service
  • Advertise
  • About
  • Contact Us

PHP Multiple Email Attachments with Sending Email AJAX Multiple File upload

June 22, 2018 Pakainfo Programming, Mysql, Mysqli Leave a comment

PHP Multiple Email Attachments with Sending Email AJAX Multiple File upload

Contents

  • PHP Multiple Email Attachments with Sending Email AJAX Multiple File upload
    • Full Source code
    • Related posts

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.

Also Read This πŸ‘‰   PHP Contact Form Send Email File Attachment Example

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

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

Also Read This πŸ‘‰   Capture Webcam Image with PHP and jQuery

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 posts:

  1. Send email using nodejs and express in Nodemailer steps
email with multiple attachments (html5 php) downloadmultiple file attachment in php in emailphp code to send email with attachmentphp form with multiple attachmentsphp send html email with multiple attachmentsphpmailer multiple attachment examplesend multiple attachment in email using phpwrite a program in php to send an email along with attachment

Post navigation

Previous Post:PHP Facebook Graph API GET comments hide-delete comments
Next Post:paypal payment Gateway Integration with laravel 5.5 -Paypal checkout Laravel

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (93) Education (63) Entertainment (130) fullform (87) Google Adsense (64) Highcharts (77) History (40) Hollywood (109) JavaScript (1359) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1035) Mysqli (894) php (2133) Programming (2344) Python (99) Software (178) Software (90) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (145) Technology (2414) Tips and Tricks (130) Tools (213) Top10 (502) Trading (93) Trending (75) VueJs (250) Web Technology (111) webtools (197) wordpress (166) World (341)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

Β© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites