0

我有一个时事通讯系统,所以当我想向所有订阅者发送消息时,我通过一个名为 .php 的 php 文件发送它post-processing.php

这是我的post-processing.php代码:

$count=$dbo->prepare("select * from sw_post where post_id=:post_id");
$count->bindParam(":post_id",$post_id,PDO::PARAM_INT,4);

if($count->execute()){
   echo " Success <br>";
   $row = $count->fetch(PDO::FETCH_OBJ);
   $sub=$row->sub;
   $post=$row->post;
} else {
   echo "Database Error ..";
print_r($count->errorInfo()); 

exit;
}
/////////////////////////

$dtl="";

$dtl .=$post. "\n\n";


@$headers.="Reply-to: $from_email\n"; 
$headers .= "From: $from_email\n"; 
$headers .= "Errors-to: $from_email\n"; 
//$headers = "Content-Type: text/html; charset=iso-8859-1\n".$headers;
// Above line is required to send HTML email 
$sql="select email_id, email from sw_email where status='A'"; 
$i=0;

foreach ($dbo->query($sql) as $row) {
   $url=$base_url."unsubscribe.php?email_id=$row[email_id]&email=$row[email]&todo=delete";
   $dtl .= "Click on the URL to unsubscribe  $url ";

假设我有三个订阅者,当我收到电子邮件时,我得到以下结果:

Click on the URL to unsubscribe: http://#.com/unsubscribe.php?email_id=1&email=example1@email.com&todo=delete
Click on the URL to unsubscribe: http://#.com/unsubscribe.php?email_id=2&email=example2@email.com&todo=delete
Click on the URL to unsubscribe: http://#.com/unsubscribe.php?email_id=3&email=example3@email.com&todo=delete

但我想要的结果只有:

Click on the URL to unsubscribe: http://#.com/unsubscribe.php?email_id=1&email=example@email.com&todo=delete

我不希望recipent 收到取消订阅我所有订阅者的链接。我该如何解决?

4

2 回答 2

1

获取用户列表后在 foreach 中绑定您的电子邮件代码

  @$headers.="Reply-to: $from_email\n"; 
  $headers .= "From: $from_email\n"; 
  $headers .= "Errors-to: $from_email\n"; 
//$headers = "Content-Type: text/html; charset=iso-8859-1\n".$headers;
$sql="select email_id, email from sw_email where status='A'"; 
foreach ($dbo->query($sql) as $row) {
    $dtl =$post. "\n\n";    

    $url=$base_url."unsubscribe.php?email_id=$row[email_id]&email=$row[email]&todo=delete";
    $dtl .= "Click on the URL to unsubscribe  $url ";

    mail('to_email','subject',$dtl,$headers); //this is your mail function
}
于 2016-02-18T11:02:39.400 回答
0

您需要做的是将消息正文保留在订阅者循环之外的变量中。然后,您一一阅读其电子邮件地址,将消息和链接附加到新变量。仅使用该电子邮件地址作为接收者并使用该新变量作为正文来调用邮件函数。当循环循环时,它将创建一个带有消息正文的新变量和一个指向该其他订阅者的新链接。

于 2016-02-18T11:19:59.080 回答