Php 无法每天生成自动邮件

Php 无法每天生成自动邮件,php,email,phpmailer,Php,Email,Phpmailer,我无法每天生成自动邮件。问题是它无法自动生成它。我有一种每天都会生成的代码。同样的细节。除了数据库查询之外,代码完全相同 这是我的密码: <?php session_start(); require("../connect.php"); /* require files for MAIL */ require("class.phpmailer.php"); require("class.smtp.php"); /* require files for MAIL ENDS */

我无法每天生成自动邮件。问题是它无法自动生成它。我有一种每天都会生成的代码。同样的细节。除了数据库查询之外,代码完全相同

这是我的密码:

    <?php
session_start();
require("../connect.php");

/* require files for MAIL */
require("class.phpmailer.php");
require("class.smtp.php");
/* require files for MAIL ENDS */



/******** Get the list of audits done in week risk category falls under High Risk and during the previous visit also the location was under High risk category ----mail on every Saturday**********/

    $current_date = date('Y-m-d');
    //$current_date ='2015-08-22';;
    /*$start_time = time() - (6*86400);
    $start_dt = date('Y-m-d',$start_time);*/

      $pagent_array = array();
     $query="Select * from `location_details` ld
    Left Join `answer_general_qc` ans_general on ans_general.lid=ld.id
    Left Join `audit_general` general on general.qtno = ans_general.qt
    Left Join `audit_general_option` general_opt on general_opt.opt_id = ans_general.ans_remark
    where ld.completed ='1' and ld.priority != 'qc' and general.qtno ='1' and ans_general.opt = 'no'  and
    STR_TO_DATE(ld.`date_audited`,'%d-%m-%Y') = '".$current_date."'";   
    $result=mysql_query($query);

    $th_style="border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #666666;
    background-color: #dedede";
    $td_style="border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #666666;
    background-color: #ffffff";
    $table_result .="<table  align='center' rules='all' style='font-family: verdana,arial,sans-serif;font-size:11px;color:#333333;border-width: 1px;border-color: #666666;border-collapse: collapse;' border='1';>
            <thead>
            <tr>
            <th style='".$th_style."'>Sr No</th>
            <th style='".$th_style."'>Location Code</th>
            <th style='".$th_style."'>Location Name</th>
            <th style='".$th_style."'>PAgent</th>
            <th style='".$th_style."'>Address 1</th>
            <th style='".$th_style."'>Address 2</th>
            <th style='".$th_style."'>District</th>
            <th style='".$th_style."'>State</th>
            <th style='".$th_style."'>Priority</th>
            <th style='".$th_style."'>Remark by TO</th>
            <th style='".$th_style."'>Remark by TO</th>
            </tr>
            </thead>
            <tbody>";
            $sr_no=1;
    if(mysql_num_rows($result) != 0)
    {           
    while($row=mysql_fetch_array($result))
    { 

            if($row['option_text'] == "")
            {
              $option_text="Other";
            }
            else
            {
              $option_text=$row['option_text'];
            }
            $table_result .= "
            <tr>
            <td style='".$td_style."'>".$sr_no."</td>
            <td style='".$td_style."'>".$row['location']."</td>
            <td style='".$td_style."'>".$row['agent']."</td>
            <td style='".$td_style."'>".$row['pagent']."</td>
            <td style='".$td_style."'>".$row['address1']."</td>
            <td style='".$td_style."'>".$row['address2']."</td>
            <td style='".$td_style."'>".$row['district']."</td>
            <td style='".$td_style."'>".$row['state']."</td>
            <td style='".$td_style."'>".$row['priority']."</td>
            <td style='".$td_style."'>".$option_text."</td>
            <td style='".$td_style."'>".$row['qc_remark']."</td>
            </tr>";
            $sr_no++;
    }
    }
    else
    {
     $table_result .="<tr><td colspan='9' align='center'>No Locations Found</td></tr>";
    }
     $table_result .="</tbody>
                     </table>";

    //  echo $table_result;     exit;

        /* Code to send MAIL */
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->Host = "host";

        $mail->SMTPAuth = true;
        //$mail->SMTPSecure = "ssl";
        $mail->Port = 25;
        $mail->Username = "Username";
        $mail->Password = "Password";

        $mail->From = "From";
        $mail->FromName = "Name";

        $mail->AddAddress("Email");

        $mail->AddBCC("Email CC");



        $body = "Dear All,<br /><br />For the review conducted on ".date('d-m-Y',strtotime($current_date))." in the following locations we have found deviation in question 1.1 (ie Does this location exist exactly at the address provided?) <br /><br /><br /><br />";
        $body .= $table_result;
        $body .= "<br /><br />Warm Regards <br /><br />

Note : Please do not reply to this email as this is an automated mail generated 
";

        //end body


        $mail->IsHTML(true);
        //$mail->Subject = "Ref : RC1/HR/".strtoupper($pa)."/".date('F Y',(time()-(5*86400)));
        $mail->Subject = "Ref : Lrr 1.1 deviation";
        $mail->Body = $body;
        //$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

        if(!$mail->Send())
        {
            echo "Message could not be sent. <p>";
            echo "Mailer Error: " . $mail->ErrorInfo;
            exit;
        }

        /* Code to send MAIL Ends */



        //mail($to,$subject,$message,$headers);
        echo 'Mail sent to '.$pa.'<br /><br />';


    /****** END of sending mail **********/


?>

如果您希望定期或每天发送邮件,理想的方法是使用cron job发送邮件。通过使用cron,您可以指定希望cron在哪个应用程序上运行。此外,您还可以指定希望邮件发送的确切时间。
请参阅此处。

希望能有帮助

$result=mysql\u查询($query)之后使用
若要确定您的问题所在,请尝试打印SQL查询并在phpMyAdmin中进行测试。您实际上没有说明问题所在,也没有提供任何错误输出。