【问题标题】:send unique email content to multiple recipients using php mysql使用 php mysql 将唯一的电子邮件内容发送给多个收件人
【发布时间】:2015-11-30 06:52:32
【问题描述】:

我想向多个用户发送唯一的确认链接,该用户列表来自数据库 mysql。我尝试使用以下代码,但它只发送第一个用户而不是全部。

<?php

  $get_ref_q = mysql_query("select * from $referal_details where ser_fk='$last_insert_id'");
  $get_last_ref_value = mysql_num_rows($get_ref_q);

  $z=1;
  if($get_last_ref_value > 0)
  {
    //$user_email = array();
    while($sel_per_fet = mysql_fetch_assoc($get_ref_q))
    {

      $rf_name = $sel_per_fet['rf_name'];
      $dy_link = $sel_per_fet['dy_link'];

      $user_email = $sel_per_fet['rf_email'];

      $userhtml = '<html>
        <body style="width:100%; font-family:Arial; font-size:13px; line-height:22px; background:#fff;  position:relative;color:#555555; margin:0px; padding:0px;">

          <div style="margin:0 auto; width:600px;">
            <div style="background:#fff; width:594px; float:left;border:#2fb25d 3px solid;">
              <div style="padding:27px; width:540px; float:left;text-align:center; border-bottom:#2fb25d 3px solid;">

              </div>
              <div style="background:#fff; padding:44px 34px; width:526px; float:left;">
                <h1 style="color:#000; font-size:20px; font-family:Arial; font-weight:normal; margin-bottom:20px;">
Dear '.$rf_name.' <br />
                </h1>

                <p>Vetri has refered you for this servey</p>
                <p>please find your servey link</p>
                <p><a href="'.$uri.'/index.php?token='.$dy_link.'">'.$uri.'/index.php?token='.$dy_link.'</a></p>

              </div>
            </div>
          </div>

        </body>
      </html>';

      $user_subject = 'Vetri has refered you for this servey';
      $user_message = $userhtml;
      $user_headers  .= 'MIME-Version: 1.0' . "\r\n";
      $user_headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
      $user_headers .= "From: Servey <$comp_email> \r\n";
      mail($user_email,$user_subject,$user_message,$user_headers,"-f$comp_email");
      $z++;
    }
  }
?>

注意:我已经有$last_insert_id 值。我想向每个用户发送独特的电子邮件内容,而不是常见的竞争。提前致谢。

【问题讨论】:

  • 绝对确定您的查询返回多行吗?
  • 您的表中有多个条目具有相同的ser_fk?

标签: php mysql email while-loop


【解决方案1】:

您的代码看起来不错 - 除了一个小问题:

$user_headers  .= 'MIME-Version: 1.0' . "\r\n";
---------------^

此行不需要.,很可能后续邮件会在$user_headers中添加越来越多相同的标头,导致后续邮件失败。

【讨论】:

  • 我试过了,但它不起作用。还是第一个人只收到了邮件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-19
  • 2019-06-17
  • 2016-08-21
  • 1970-01-01
  • 2014-02-06
  • 2016-08-11
  • 1970-01-01
相关资源
最近更新 更多