电子邮件表单根据附件发送多个邮件 [英] Email form sends multiple mails depending on attachments
问题描述
所以基本上我想要一个电子邮件系统可以发送一个或多个图片的消息,我现在的问题是,当我上传我们说4张图片,表单发送给我4个电子邮件,同一个文本,但一个图片一次我想让他们全部添加为4个附件到1个电子邮件,而不是1个附件到4封电子邮件。
So basically I want an email system that can send a message with one or more pictures, the problem I have now is that when I upload let's say 4 pictures, the form sends me 4 emails with both the same text but one picture at a time. I want them all to be added as 4 attachments to 1 email, not 1 attachment to 4 emails.
这是我的HTML:
<form id="upload" method="post" action="upload.php">
<div id="drop">
Onderwerp<br>
<input name="txtSubject" type="text" id="txtSubject" /><br>
Omschrijving<br>
<textarea name="txtDescription" cols="30" rows="4" id="txtDescription"></textarea><br>
Voeg afbeeldingen toe
<input type="file" name="fileAttach" multiple accept="image/*;capture=camera" />
<input type="submit" name="Submit" value="Send">
</div>
<ul>
<!-- The file uploads will be shown here -->
</ul>
</form>
这里是我的PHP:
<?
$strTo = "email@email.com";
$strSubject = $_POST["txtSubject"];
$strMessage = nl2br($_POST["txtDescription"]);
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
$flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error //
if($flgSend)
{
echo "Mail send completed.";
}
else
{
echo "Cannot send mail.";
}
?>
我对PHP不是太好,我拿了一个多图像上传器,并尝试使其成为邮寄表单,除了多个电子邮件发送部分外,还有其他工作。
I'm not that great with PHP, I took an multiple image uploader and tried to make it into a mailing form, wich works.. except for the multiple email sending part.
任何帮助都非常感谢! :
Any help is greatly appreciated! :)
推荐答案
尝试一下:
for($i=0;$i<count($_FILES["fileAttach"]["name"]);$i++)
{
if($_FILES["fileAttach"]["name"][$i] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"][$i];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"][$i])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
}
这篇关于电子邮件表单根据附件发送多个邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!