我想同時發送多個電子郵件。它在某些時候不起作用。多個電子郵件附件不起作用
幫助我....
# DYNAMICALLY GET ALL ATTACHMENTS
for($i=1;$i<count($_FILES)+1; $i++){
if(!empty($_FILES['atachment'.$i]['tmp_name'])){
$file_name = $_FILES['atachment'.$i]['name'];
$temp_name = $_FILES['atachment'.$i]['tmp_name'];
$file_location = $_FILES['atachment'.$i]['tmp_name'];
$filetype = $_FILES['atachment'.$i]['type'];
move_uploaded_file($temp_name,'temp_upload/'.$file_name);
$files[] = 'temp_upload/'.$file_name;
}
}
# EMAIL SETTING
$headers = "From:$from";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$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";
# PREPARE ATTACMENTS
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],"rb");
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "–{$mime_boundary}–\n";
}
# CHECK IF SEND FUNCTION
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>mail sent to $to!</p>";
} else {
echo "<p>mail could not be sent!</p>";
} enter code here
不完全是你的問題的答案,但我想你可能想用http://swiftmailer.org/ – swordfish
做這樣的事情爲什麼'@'使用'mail()'函數?將其移除以查看發送時發生的警告/錯誤 - 這應該有助於您理解問題的原因。 – kpower
郵件()已通電,不建議使用此功能。有些東西讓自己的套接字連接到像phpmailer這樣的郵件服務器是一個更好的主意。 – 2011-08-26 05:14:21