所以我有这个代码可以在没有“文件附件”的情况下完美运行,并将输入 html 的消息发送给 MYSQL DB 中的所有收件人,但是当我插入附件代码时,邮件只会发送给一个收件人。请帮帮我:)
<html>
<head>
<title>test</title>
</head>
<body>
<?
mysql_connect("localhost", "root", "mypass") or die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$sql = mysql_query("SELECT * FROM mytable");
while($row = mysql_fetch_array($sql)){
$email = $row["email"];
$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($email,$strSubject,null,$strHeader); // @ = No Show Error //
if($flgSend)
{
echo "Task Complete. Your emails are being forwareded to your clients";
}
else
{
echo "Error!!! Task incomplete. Please contact website maintainer.";
}
?>
</body>
</html>