doubiao7267 2017-09-20 16:56
浏览 43
已采纳

正在合并单独的电子邮件

I am trying to send emails using PHP using data from a database. The issue I am having is that the emails are being combined for each subsequent result match. So if I have 3 users that have the same match criteria, Yes/Yes for example, the first email is clean, the 2nd email contains the contents of the first then second email and the third recipient contains the first, second then third. I am not sure why it is combining messages, but obviously would like it to stop. :-)

<?php
$servername = "intentionally empty";
$username = "intentionally empty";
$password = "intentionally empty";
$dbname = "intentionally empty";
$tblname = "intentionally empty";
$email_to = "";
$email_subject = "";
$email_message = "";
$email_from = "";

        $conn = mysqli_connect($servername, $username, $password, $dbname) or die("Unable to Connect to '$dbhost' - Please email support@domain.com");

    $sql = "SELECT * FROM $tblname WHERE Active='Yes' AND Reqested='Yes'";
    $result = mysqli_query ($conn, $sql);
    if (!mysqli_query($conn, $sql))
    {
        echo "Error: " . mysqli_query_error();
    }

    while($row = mysqli_fetch_array($result)){
        $first_name = $row['First'];
        $last_name = $row['Last'];
        $dob = $row['DOB'];
        $variableA = $row['VarA'];
        $variableB = $row['VarB'];
        $email_to = $row['Email'];

    $email_from = "support@domain.com"; 
    $email_subject = "Reminder: Requested information for $dob - $varA";
    $email_intro .= "Hello $first_name $last_name,
";
    $email_intro .= "
";
    $email_intro .= "This is your monthly request reminder that for $dob - $varA
";
    $email_intro .= "
";
    $email_var .= "If you have already sent your updates then you can disregard.
";
        $email_end .= "
";
    $email_end .= "Please let us know if you have any question.
";
    $email_end .= "
";
    $email_end .= "Thank you,
";
    $email_end .= "Management.
";

    $email_message .= "$email_intro$email_var$email_end";

// create email headers
if (@mail($email_to, $email_subject, $email_message, 'From:' . $email_from));

echo 'Email sent to: ' . $email_to. '<br>';

}

?>
  • 写回答

2条回答 默认 最新

  • duanjiagu0655 2017-09-20 17:35
    关注

    Post Successfully Email sent message you can reinitialize or set the value of variable $email_message as Null.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 cruise如何仿真不同温度下车辆的经济性?
  • ¥20 扑克牌游戏的完整代码
  • ¥88 求帮安装Python架构的vnpy
  • ¥20 逻辑回归法分析品牌知名度和购买意向
  • ¥15 华为云主机-异常连接
  • ¥50 vue 成绩列表 输入成绩,并统计各分数段人数
  • ¥20 请教怎么绕过这个卡密系统 大家交流一下
  • ¥15 设计数字电路得到要求结果
  • ¥15 hfss 组天线阵列报错:The A and B vectors must be parallel to the XY plane,如何解决?
  • ¥30 ansible连接设备报错