【问题标题】:PHP send email foreach userPHP为每个用户发送电子邮件
【发布时间】:2017-02-01 10:24:02
【问题描述】:

对于这个页面,我需要从用户那里获取经理的电子邮件,并将电子邮件发送到每个经理的电子邮件,其中 endofmonthdate = 22/09/2016

http://pastebin.com/7PD2MyuC

提前谢谢你!!

【问题讨论】:

  • endofmonthform 的列数据类型 ???? DATE 或 DATETIME 或 VARCHAR?
  • @devpro Varchar
  • 在 php my admin 中运行您的查询,您会明白的。 SELECT * FROM clients` WHERE endofmonthform="22/09/2016"`
  • 我已经做到了。那不是问题。问题是选择每个经理的电子邮件并将电子邮件发送给每个经理,而不仅仅是一个

标签: php mysql sql email foreach


【解决方案1】:

您的代码缺少一些大括号 ( {} ):

include ("../dbconnect.php");

$sql='SELECT c.endofmonthform, c.startofmonthform, c.email, c.id, c.formlevel, c.mastersite, c.opmanager, u.userEmail FROM `clients` as c LEFT JOIN `users` as u on c.opmanager = u.userName WHERE endofmonthform="22/09/2016"'; //TODAYS DATE BACK HERE!

$result=mysql_query($sql); 

 while($row=mysql_fetch_array($result)){  

    $enddate = $row['endofmonthform']; // End

    $startdate = $row['startofmonthform']; // Start

    $email = $row['email']; //Email to send email to

    $id = $row['id'];

    $formlevel = $row['formlevel']; //To update and check formlevel

    $sitegroupname = $row['mastersite'];

    $manager = $row['opmanager'];

    $opemail = $row['userEmail'];

    /* If end date is today and form level is still ZERO then send email to op manager */
    $mail = new EMail;

    $mail->Username = 'Sender email';    
    $mail->Password = 'mypwd';
    $mail->SetFrom("senderemail@example.com","companyname");  
    $mail->ContentType = "text/html";
    $mail->Subject = "Client feedback incomplete NEW LAYOUT";

    //Enter the email address you wish to send TO (Name is an optional friendly name):
    $mail->AddTo($opemail,$manager);


    $mail->Message = "<!DOCTYPE html PUBLIC  -//W3C//DTD XHTML 1.0 Transitional//EN   http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >
    <html xmlns=http://www.w3.org/1999/xhtml>
    <head>
    <meta http-equiv=Content-Type  content=text/html; charset=utf-8 />
    <title></title>
    <style type=text/css >
    body {margin: 0; padding: 0; min-width: 100%!important;}
    .content {width: 100%; max-width: 600px;}  
    </style>
    </head>
    <body yahoo bgcolor=#f6f8f1 >
    <table width=100% bgcolor=#f6f8f1 border=0 cellpadding=0 cellspacing=0>
    <tr>
    <td>
    <table class=content  align=center  cellpadding=0  cellspacing=0  border=0 >
    <tr>
    <td>

    ID: ".$id." <br>

    Clients group name: ".$sitegroupname." <br>

    Managers Name: ".$manager." <br>

    Managers Email: ".$useremail." <br>

    Please log into your account as you have feedback notifications
    <br>

    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </body>
    </html>";

    echo $success = $mail->Send(); //Send the email.
}

还清理了一些 PHP 以简化整个事情。 注意:我排除了电子邮件类,因为它与此问题无关。

编辑:

TS 通知我邮件部分无法正常工作,因此请尝试使用默认的 php 邮件程序:

<?php 
include ("../dbconnect.php");

$sql='SELECT c.endofmonthform, c.startofmonthform, c.email, c.id, c.formlevel, c.mastersite, c.opmanager, u.userEmail FROM `clients` as c LEFT JOIN `users` as u on c.opmanager = u.userName WHERE endofmonthform="22/09/2016"'; //TODAYS DATE BACK HERE!

$result=mysql_query($sql); 

 while($row=mysql_fetch_array($result)){  

    $enddate = $row['endofmonthform']; // End

    $startdate = $row['startofmonthform']; // Start

    $email = $row['email']; //Email to send email to

    $id = $row['id'];

    $formlevel = $row['formlevel']; //To update and check formlevel

    $sitegroupname = $row['mastersite'];

    $manager = $row['opmanager'];

    $opemail = $row['userEmail'];

    mail($opemail, "subject", "message", "from");
}

【讨论】:

  • 感谢您的帮助!真的很感激
  • 没问题,很高兴我能提供服务:)
猜你喜欢
  • 1970-01-01
  • 2016-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-16
  • 2011-05-21
  • 1970-01-01
相关资源
最近更新 更多