The code below sends only one attachment, but I need to attach and send two file(one rar file and pdf)

$email_to = "$email"; // The email you are sending to (example)
$email_from = "online@tryteksolutions.co.in"; // The email you are sending from (example)
$email_subject = "subject line"; // The Subject of the email
$email_txt = "text body of message"; // Message that the email has in it
$fileatt = "files/TRYTEK.rar"; // Path to the file (example)
$fileatt_type = "application/x-rar-compressed"; // File Type
$fileatt_name = "download.rar"; // Filename that will be used for the file as the attachment
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers="From: $email_from"; // Who the email is from (example)
$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;
$email_message .= "\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";

mail($email_to,$email_subject,$email_message,$headers);

Recommended Answers

All 5 Replies

reply me friend give me some solution for the above question

just do the same for the pdf as you did for the rar.
you will need a different fileatt_type (just google that)
don't forget the --{$mime_boundary}\n

Daniweb is waste no one is replying. stackoverflow is good

Daniweb is waste no one is replying. stackoverflow is good

You're just being impatient. Apart from that, if you post the above on SO it will be closed in no time.

What have you tried? Did you even try pzuurveen's suggestion? People here will guide you, but not provide a solution so you can continue.

Closed thread, continued here:
http://www.daniweb.com/web-development/threads/474764/php-send-mail-with-two-attachment-already-exist-in-server

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.