我使用以下代码使用phpmailer发送包含多个附件的电子邮件。电子邮件已发送,但没有附件。我不知道为什么。没有错误。
<?php
if(isset($_POST['submit']))
{
include "class.phpmailer.php";
$mail = new PHPMailer();
$From = "madeeha.rehman5@gmail.com";
$FromName = "madhya";
$To = "madeeha.rehman5@gmail.com";
$ToName = "To Name";
$Subject = "hello";
$Body = "Hy, hello";
$numFiles = count(array_filter($_FILES['attachment']['name']));
for ($i = 0; $i < $numFiles; ++$i)
{
$mail->AddAttachment($_FILES['attachment']['tmp_name'][$i], $_FILES['attachment']
['name']);
}
$mail->From = $From;
$mail->FromName = $FromName;
$mail->AddAddress($To , $ToName);
$mail->WordWrap = 50; // set word wrap
$mail->Priority = 1;
$mail->IsHTML(true);
$mail->Subject = $Subject;
$mail->Body = $Body;
if(!$mail->Send())
{ echo "Mailer Error: " . $mail->ErrorInfo;}
else
$mail->Send();
echo ("Message is sent");
}
?>
我正在使用的java脚本函数是:
<script type="text/javascript">
var upload_number = 1;
var attachmentlimit = 5;
function addFileInput() {
var d = document.createElement("div");
var file = document.createElement("input");
file.setAttribute("type", "file");
file.setAttribute("name", "attachment[]");
d.appendChild(file);
document.getElementById("moreUploads").appendChild(d);
upload_number++;
if(upload_number == attachmentlimit) {
document.getElementById('moreUploadsLink').style.display='none';
}
}
</script>
和
<input type="file" name="attachment[]" id="attachment" size="30"
onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />