[英]Email form sends multiple mails depending on attachments
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. 因此,基本上我想要一个可以发送包含一幅或多幅图片的消息的电子邮件系统,现在的问题是,当我上传4张图片时,该表单向我发送了4封电子邮件,其中包含相同的文本,但一次只能发送一张图片。 I want them all to be added as 4 attachments to 1 email, not 1 attachment to 4 emails. 我希望将它们全部添加为1个电子邮件的4个附件,而不是4个电子邮件的1个附件。
Here is my HTML: 这是我的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>
and here is my PHP: 这是我的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.";
}
?>
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. 我对PHP不太满意,我使用了多个图片上传器,并尝试将其制作为邮件形式,这很有效..除了多个电子邮件发送部分。
Any help is greatly appreciated! 任何帮助是极大的赞赏! :) :)
try something like: 尝试类似:
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";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.