How can I send multiple attachment using these code?

Viewed 11

Can anyone tell me how can I send multiple attachments using these codes? I have used the same code and I am able to send only one attachment. But I want to send two or multiple attachments. Someone, please help me. What do I need to change here?

<?php

$filenameee =  $_FILES['id_photo']['name'];
$fileOneName = $_FILES['id_photo']['tmp_name']; 


// $message ="Name = ". $name . "\r\n  Email = " . $email . "\r\n Message =" . $usermessage; 

$subject ="A New ID Submitted";
$fromname ="A user";
$fromemail = 'trackingothers90@gmail.com';  //if u dont have an email create one on your cpanel

$mailto = 'nabilsiddik90@gmail.com';  //the email which u want to recv this email




$content = file_get_contents($fileOneName);
$content = chunk_split(base64_encode($content));

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (RFC)
$eol = "\r\n";

// main header (multipart mandatory)
$headers = "From: ".$fromname." <".$fromemail.">" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
$headers .= "This is a MIME encoded message." . $eol;

// message
$body = "--" . $separator . $eol;
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $eol;
$body .= $eol;

// attachment
$body .= "--" . $separator . $eol;
$body .= "Content-Type: application/octet-stream; name=\"" . $filenameee . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment" . $eol;
$body .= $content . $eol;
$body .= "--" . $separator . "--";

//SEND Mail
if (mail($mailto, $subject, $body, $headers)) {
    echo "mail send ... OK"; // do what you want after sending the email
    
    
} else {
    echo "mail send ... ERROR!";
    print_r( error_get_last() );
}
0 Answers
Related