Jump to content

Help with Multiple Email Attachments


thisagain

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:

[code]
<?php

$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));
fclose($file1);
// 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 .
            "\n\n";
// 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" .
            "--{$mime_boundary}--\n";
}
// Send the message
$ok = @mail($to, $subject, $message, $headers);
if ($ok){
echo '<p>Thank you for sending your Model Submission.</p>';
}
else{
echo '<p>Mail could not be sent.</p>';
}
?>

[/code]

Any help would be great.  Thanks
Link to comment
Share on other sites

Have a look at [url=http://codewalkers.com/seecode/231.html]http://codewalkers.com/seecode/231.html[/url]

Description:
[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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.