多次发送带有附件的电子邮件-重新发布 [英] Multiple sending of email with attachment - repost
问题描述
我重新发布此帖子,因为没有人回答我以前的帖子.
I am re-posting this because no one answered my previous post.
我正在尝试将电子邮件发送给带有各自pdf文件的多个收件人.我成功地向多个收件人发送了电子邮件,但是收件人收到了多封电子邮件.收件人收到的电子邮件数量就是我数据库中存储的电子邮件地址的数量.
I am trying to send emails to multiple recipients with respective pdf files attached. I was successful with sending emails to multiple recipient but the recipients receive multiple emails. The number of emails received by a recipient is the number of email addresses stored in my database.
我遇到的第二个问题是发送给收件人的附件都是相同的文件.情况应该是这样的:收件人A的电子邮件应附有pdf A,收件人B的应附有pdf B,依此类推.
The second problem that I have encountered was that the attachment sent to the recipients were all the same file. The scenario should be like this: recipient A should have email attached with pdf A, recipient B with pdf B, so on and so fort.
那些pdf的文件名与每个收件人具有的唯一控制号相对应.例如.收件人A的控制号为1234,因此其pdf名称为1234.pdf.
Those pdf's have file names that correspond to the unique control number that each recipient has. E.g. recipient A has control number 1234, so his pdf is named as 1234.pdf.
我试图在$ ctrl_no = mysql_result($ ctrl,0)中执行一次循环,但是它给出了一个错误,提示服务器的内存已达到极限.
I tried to do a wile loop in $ctrl_no = mysql_result($ctrl, 0) but it gives an error saying that the memory limit of the server has reached.
希望您能帮助解决我的两个问题.
Hope you could help solve my 2 problems.
$input = addslashes($_POST['dep']);
$email = "select email_address from student y where y.center = '$input'";
if ($p_address=mysql_query($email))
{
while($row = mysql_fetch_array($p_address))
{
$mail->AddAddress($row[0]);
$input = addslashes($_POST['dep']);
$control = "select control_no from student y where y.center = '$input'";
if($ctrl=mysql_query($control)){
$ctrl_no = mysql_result($ctrl, 0);
$mail->AddAttachment("reports/".$ctrl_no.".pdf");
}
else{
echo "No attached pdf.";
}
更新:$ mail功能
require_once('phpmailer/class.phpmailer.php');
include("phpmailer/class.smtp.php");
$mail = new PHPMailer();
$body = file_get_contents('phpmailer/body.html');
$body = preg_replace('/\/b]/','',$body);
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "me@gmail.com";
$mail->Password = mypass;
$mail->SetFrom("me@gmail.com", "Office");
$mail->AddReplyTo("me@gmail.com"," Office");
$mail->Subject = "My Subject";
$mail->AltBody = "Subject file";
$mail->MsgHTML($body);
推荐答案
<?php
$i = 0;
while($view = mysqli_fetch_array($result)){
$i++; ?>
<tr>
<td>
<label><?php echo $i . ". " . $view['name']; ?> </label>
</td>
<td>
<input type="text" name="receiverEmail<?php echo $i; ?>" id="receiverEmail<?php echo $i; ?>" value="<?php echo $view['email'] ?>" readonly style="width: 300px">
</td>
<td>
<input type="file" name="receiverFile<?php echo $i; ?>" id="receiverFile<?php echo $i; ?>">
</td>
</tr>
<tr style="height: 5px"></tr>
<?php }?>
<tr style="height: 15px"></tr>
<tr>
<td></td>
<td></td>
<td style="float: right">
<input type="submit" name="submit" id="submit">
</td>
</tr>
</form>
这篇关于多次发送带有附件的电子邮件-重新发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!