Jump to content


This topic is now archived and is closed to further replies.


Help with Multiple Email Attachments

Recommended Posts

I've managed to make my webform email form information and one attachment file but I want to make it add more than one file attachments.

Can someone please help get me started on how to do this?

My code is:


$to = 'myemail@someplace.com';
$from = 'My Webform';
$subject = 'Webform Submission - ALERT';

// Read POST request params into global vars
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];

$message = "Someone has submitted something via webform";

// Obtain file upload vars
$photo1      = $_FILES['photo1']['tmp_name'];
$photo1_type = $_FILES['photo1']['type'];
$photo1_name = $_FILES['photo1']['name'];

$headers = "From: $from";

if (is_uploaded_file($photo1)){
// Read the file to be attached ('rb' = read binary)
$file1 = fopen($photo1,'rb');
$data1 = fread($file1,filesize($photo1));
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
            "Content-Type: multipart/mixed;\n" .
            " boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
            "--{$mime_boundary}\n" .
            "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
            "Content-Transfer-Encoding: 7bit\n\n" .
            $message .
// Base64 encode the file data
$data1 = chunk_split(base64_encode($data1));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
            "Content-Type: {$photo1_type};\n" .
            " name=\"{$photo1_name}\"\n" .
            //"Content-Disposition: attachment;\n" .
            //" filename=\"{$photo1_name}\"\n" .
            "Content-Transfer-Encoding: base64\n\n" .
            $data1 .
            "\n\n" .
// Send the message
$ok = @mail($to, $subject, $message, $headers);
if ($ok){
echo '<p>Thank you for sending your Model Submission.</p>';
echo '<p>Mail could not be sent.</p>';


Any help would be great.  Thanks

Share this post

Link to post
Share on other sites
Have a look at [url=http://codewalkers.com/seecode/231.html]http://codewalkers.com/seecode/231.html[/url]

[quote]PHP Email Attachment v2 by Christoph2k on 01/16/03
This code will allow you to send an email using PHP and include multiple attachments with it! Its really simple to use! [/quote]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.