Hi Team
I need help, how do i send attachments as pdf to the mail recepient? My code is not sending attachment but only show total attachment size from the email.
// logic
PHP
";
$headers = "From: $from";
// Boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Headers for attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// Multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
// Preparing attachment
if(!empty($received_email_send)){
for($i=0;$i
Total Attachments: '.count($received_email_send).'
';
// Call function and pass the required arguments
$sendEmail = multi_attach_mail($to, $subject, $htmlContent, $from, $fromName, $received_email_send);
// Email sending status
if($sendEmail){
echo 'The email is sent successfully.';
}else{
echo 'Email sending failed!';
}
?>
Arvind YadavRank #880 · 2.5K reputationPosted Mar 7, 2023, 2:18 PM EST
// Define the message body $body = '--'.$separator.$eol; $body .= 'Content-Type: text/plain; charset="iso-8859-1"'.$eol; $body .= 'Content-Transfer-Encoding: 8bit'.$eol.$eol; $body .= $message.$eol; // Define the first attachment $file = 'path/to/attachment1.pdf'; $file_size = filesize($file); $file_name = basename($file); $handle = fopen($file, 'rb'); $content = fread($handle, $file_size); fclose($handle); $attachment = chunk_split(base64_encode($content)); $body .= '--'.$separator.$eol; $body .= 'Content-Type: application/pdf; name="'.$file_name.'"'.$eol; $body .= 'Content-Transfer-Encoding: base64'.$eol; $body .= 'Content-Disposition: attachment; filename="'.$file_name.'"'.$eol.$eol; $body .= $attachment.$eol; // Define the second attachment $file = 'path/to/attachment2.doc'; $file_size = filesize($file); $file_name = basename($file); $handle = fopen($file, 'rb'); $content = fread($handle, $file_size); fclose($handle); $attachment = chunk_split(base64_encode($content)); $body .= '--'.$separator.$eol; $body .= 'Content-Type: application/msword; name="'.$file_name.'"'.$eol; $body .= 'Content-Transfer-Encoding: base64'.$eol; $body .= 'Content-Disposition: attachment; filename="'.$file_name.'"'.$eol.$eol; $body .= $attachment.$eol; // Close the message $body .= '--'.$separator.'--'.$eol;Guest UserRank #877 · 2.5K reputationPosted Mar 8, 2023, 1:51 AM EST
Hi Arvind please tell where exactly must this implementation be inserted... I have made some changes below but the logic still the same, current problem now i can only get one attachment but cant view the document its not opening and need your help below. Point out by showing what needs to change etc, rest will know and test it, let you know asap.
$filenameee = $_FILES['id']['name']; $fileName = $_FILES['id']['temp_name']; $amount =$_REQUEST['amount']; $purpose =$_REQUEST['purpose']; $voucher =$_REQUEST['voucher']; $gender =$_REQUEST['gender']; $fname =$_REQUEST['fname']; $lname =$_REQUEST['lname']; $message = "Name: ". $fname . $lname . "\r\n Email: " . $email . "\r\n Cell Number: " . $number . "\r\n Monthly Income: " $subject ="Application Form"; $fromname ="ACI FINANCE"; $fromemail = $email; //if u dont have an email create one on your cpanel $mailto = '[email protected]'; //the email which u want to recv this email $content = file_get_contents($filenameee); $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." " . $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; $logo = 'img/logo.png'; $link = '#'; $body = "Express Mail"; $body .= ""; $body .= ""; $body .= " "; $body .= ""; $body .= "Name: {$fname} {$lname}"; $body .= "Email: {$from}"; $body .= ""; $body .= "CellNumber: {$number}"; $body .= ""; $body .= "Loan Amount: {$amount}"; // message $body = "--" . $separator . $eol; $body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol; $body .= "Content-Transfer-Encoding: 8bit" . $eol; $body .= $message . $eol; // attachment $body .= "--" . $separator . $eol; $body .= "Content-Type: application/pdf; name=\"" . $filenameee . "\"" . $eol; $body .= "Content-Transfer-Encoding: base64" . $eol; $body .= "Content-Disposition: attachment" . $eol; $body .= $content . $eol; $body .= "--" . $separator . "--"; $readfile.= "$filenameee"; $body .= ""; $body .= ""; //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() ); } $send = mail($to, $subject, $body, $headers); $amount =$_POST['amount']; $purpose =$_POST['purpose']; $voucher =$_POST['voucher']; $gender =$_POST['gender']; $fname =$_POST['fname']; $lname =$_POST['lname']; $title =$_POST['title'];