Page 1 of 1
PHP page sending mail..want multiple attachments
Posted: Wed Jun 06, 2007 7:32 am
by kbrown3074
I currently have a php page that sends an email with a single attachment. Is there anything special I need to do to send multiple attachments? I was thinking I can just loop through the attachment code but was wondering if there was a better way that I havent tried yet.
Posted: Wed Jun 06, 2007 7:52 am
by feyd
Are you using Swift?
Posted: Wed Jun 06, 2007 7:55 am
by Chris Corbyn
Yeah we'll need to see any code to know what you mean by "the attachment code", unless you are using Swift mailer, in which case you just call $message->attach() multiple times.
Posted: Wed Jun 06, 2007 8:19 am
by kbrown3074
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am not currently running swift. Is that a single package that I can install on the server? Below is the code that I am running for a single file..works so far with one file.
Code: Select all
function filemail($filename,$subject,$mailtxt,$mailto)
{
$fileatt = $filename; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = $filename; // Filename that will be used for the file as the attachment
$email_from = "name.com"; // Who the email is from
$email_subject = $subject; // The Subject of the email
$email_txt = $mailtxt; // Message that the email has in it
$email_to = $mailto; // Who the email is too
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
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_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 = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
}
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Wed Jun 06, 2007 10:11 am
by kbrown3074
d11wtq wrote:Yeah we'll need to see any code to know what you mean by "the attachment code", unless you are using Swift mailer, in which case you just call $message->attach() multiple times.
Just wanna say "Mad Props" on the swift mailer!! It was EXACTLY what I needed...thanks!!