Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7414265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:04:29+00:00 2026-05-29T07:04:29+00:00

I have a function to send an email with multiple word documents as attachments.

  • 0

I have a function to send an email with multiple word documents as attachments. Only problem is that no matter how many documents I send, only 1 shows up in the email, and also, it shows up as corrupted. The file path name is correct, I have tested this, but when I try to open the document from the email, Microsoft word complains about corrupted file. Somebody please tell me what I am doing wrong?

function mail_attachment_multiple($to, $subject, $message, $attachment, $from){//sends email as an attachment. attachment parameter is the path to file

$fileatt_type = "application/msword"; // File Type
$email_from = $from; // Who the email is from
$email_subject =  $subject; // The Subject of the email
$email_txt = $message; // Message that the email has in it
$email_to = $to; // Who the email is to
$headers = "From: ".$email_from;
$msg_txt="\n\n You have recieved a new attachment message from $from";

$email_message = ""; 

//loop through array: $key = filename; $value = filenamePATH
foreach($attachment as $key => $value){
    $fileatt_name = $key; //name of file
    $fileatt_path = $value; // file path (http://www.example.com/filePath)

    $file = fopen($fileatt_path,'rb');
        $temp = get_headers($fileatt_path, 1);
    $file_size = $temp['Content-Length'];           
    $data = fread($file, $file_size); //filesize($fileatt_path)
    fclose($file);

    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    $headers .= "\nMIME-Version: 1.0\n" .
        "Content-Type: multipart/mixed;\n" .
        " boundary=\"{$mime_boundary}\"";
    $email_txt .= $msg_txt;
    $email_message .= "This is a multi-part message in MIME format.\n\n" .
            "--{$mime_boundary}\n" .
            "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
           "Content-Transfer-Encoding: 7bit\n\n" .
    $email_txt . "\n\n";
    $data[$key] = chunk_split(base64_encode($data));        

    $email_message .= "--{$mime_boundary}\n" .
              "Content-Type: {$fileatt_type};\n" .
              " name=\"{$fileatt_name}\"\n" .
              //"Content-Disposition: attachment;\n" .
              //" filename=\"{$fileatt_path}\"\n" .
              "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" ."--{$mime_boundary}--\n";
}

return @mail($email_to, $email_subject, $email_message, $headers);?>

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:04:29+00:00Added an answer on May 29, 2026 at 7:04 am

    You should really use a mail library for this sort of thing. I highly recommend SwiftMailer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that uses CDO to send emails with request to have
I have a class named toto which I send to a function that does
as in asp we have function to send complete web page in email, which
I have a function that sends email using asp.net built in mail framework. I've
I have a problem creating my own librairie to send email. This is my
I have written a function which receives some parameters (email addresses) and send email.
As advised I have tried using PHP Mailer to send email attachments with a
i send ajax requests with jquery, and i have a function: $('input').ajaxSuccess(function(e, xhr, settings)
I have function getCartItems in cart.js and I want to call that function in
So I have function that formats a date to coerce to given enum DateType{CURRENT,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.