从服务器 - 用户检查表单发送的多个电子邮件附件

时间:2011-10-14 14:49:33

标签: php jquery email

我看过并试图通过许多脚本,但无法弄清楚这一个。我有一个scipt成功从服务器发送一个附件,基于用户只填写一个表单,其中只包含他们的电子邮件地址和隐藏字段,其中包含要在POST中传递的特定文件路径和文件名。现在我的新问题。

我创建了一个表单,用户可以通过电子邮件查看他们希望收到的pdf框。表单包含复选框和文本框以输入电子邮件地址。有没有人知道如何将该复选框信息作为一个数组传递给我一个php邮件脚本以包含附件。我甚至没想过附件大小。我正在使用jquery库ajax​​将表单变量提交到服务器上的脚本。

单个附件脚本的副本

$fileatt = $_POST['file'];  // post variable path to the file
$fileatt_type = "application/pdf"; // File Type
$fileatt_name = $_POST['filename']; // Filename that will be  used for the file as the attachment

$email_from = "info@test.com"; // Who the email is from
$email_subject = "Your requested materials"; // The Subject of the email
$email_message = "Thank you for requesting the 'filename'.<br>";
$email_message .= "Thanks for visiting.<br>"; // Message that the email has in it

$email_to = $_POST['email']; // Who the email is to

$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_message .= "\n\n";

$data = 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_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";

$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok) {
echo "Your file has been sent to the email address you specified.";

} else {
die("Sorry but the email could not be sent. Please try again!");
}

谢谢, Deon

0 个答案:

没有答案