向多个用户发送激活提醒电子邮件

时间:2014-03-18 00:36:12

标签: php email

我需要有关此代码的帮助,以便在用户忘记激活帐户时向他们发送电子邮件。该代码能够打印帐户未激活但仅向一个用户发送电子邮件的用户列表。谢谢!

function joinDateFilter(){
   $query = mysql_query("SELECT * FROM oc_accounts WHERE active = 2");
   $mail_to = "";
   while ($row = mysql_fetch_array($query)){
    echo $row['name']." - ".$row['email']." - ".$row['createdDate']."\n";
       $mail_to = $row['email']."";
       $account_name = $row['name']."";
       $created_date = $row['createdDate']."";
       $token = $row['activationToken']."";
   }
   if (!empty($mail_to)){
    sendEmail($mail_to,$account_name,$created_date,$token);
  }
}


function sendEmail($mail_to,$account_name,$created_date,$token) {

    $url.='http://mywebsite.com/registrar-uma-nova-conta.htm?account='.$mail_to.'&token='.$token.'&action=confirm';
    $from    = "noreply@aeroclassificado.com";
    $message="<img src='http://www.mywebsite.com/images/logo.png'><br><br>
    Prezado ".$account_name.',<br><br>
    Seu cadastro criado em '.$created_date.' ainda não foi confirmado.<br><br>
    Clique no link abaixo para confirmar sua conta e começar a anunciar<br>
    seus produtos.<br><br>
    <a href="'.$url.'">confirmar conta</a><br><br>
    http://mywebsite.com/registrar-uma-nova-conta.htm?account='.$mail_to.'&amp;token='.$token.'&amp;action=confirm<br><br>
    Thanks!';
    $headers = 'From: '.$from."\r\n" .
    'Reply-To:'.$_POST['email']."\r\n" .
    "Content-Type: text/html; charset=iso-8859-1\n".
    'X-Mailer: PHP/' . phpversion();
    mail($mail_to,"Ative sua conta! - My website",$message,$headers);

}

1 个答案:

答案 0 :(得分:0)

如果我理解正确,此代码应该向您的数据库中的多个地址发送电子邮件。在这种情况下,只需将if语句移动到while循环中:

function joinDateFilter(){
$query = mysql_query("SELECT * FROM oc_accounts WHERE active = 2");
$mail_to = "";
while ($row = mysql_fetch_array($query)){
echo $row['name']." - ".$row['email']." - ".$row['createdDate']."\n";
   $mail_to = $row['email']."";
   $account_name = $row['name']."";
   $created_date = $row['createdDate']."";
   $token = $row['activationToken']."";
if (!empty($mail_to)){
 sendEmail($mail_to,$account_name,$created_date,$token); }
 }
 }

另外,请查看http://us1.php.net/mysqli您应该将mysql命令更改为mysqli。