使用嵌套while循环时获取随机空白电子邮件

时间:2014-03-24 03:41:07

标签: php mysql email

第一,我知道mysql_已经过时了,我应该使用mysqli(不幸的是,我继承了这个系统,并且目前还有很多工作需要改变它)

我遇到的问题是当我执行代码时,我收到随机的空白电子邮件。该系统循环遍历数据库中的存储列表,并在表中列出商店经理的信息。提供什么信息并不重要。有没有人在手边看到任何导致这个问题的事情?

while($store = mysql_fetch_array($result_store)){

#Updates the Report Date for each store in the Loop
$report_date = "UPDATE ActiveStores SET Report_Date = '$Today' WHERE StoreNumber = $store[StoreNumber]";

if (!mysql_query($report_date, $con)){
    die('Error: ' . mysql_error());
}


#Selects data from ActiveStores for the current store in the loop
$result2 = mysql_query("SELECT * FROM ActiveStores WHERE StoreNumber = '$store[StoreNumber]' ORDER BY StoreNumber");

#Loops through the currently selected store and Creates an Array of the data
while ($row = mysql_fetch_array($result2)) {
    #Sets Store Variable

        $Store = $row['StoreNumber'];
    echo '<table width="1110"><table width="1102"><tr>';


    # To Email Address 

    #$emailaddress = '******@*****.com';

    # Message Subject 
        $emailsubject= 'Testing Report - Store: ' . $Store;

    #Turn on Output buffer for email
    ob_start();
    #Heading for Report
    echo '<h2 class="blktext">Walgreens Weekly Report - ' . $Today . '<br /></h2>';

    echo '<h2>Insurance Orders:</h2>';


#Cancelled Orders for the store this week   
    $result_cash_canceled = mysql_query("SELECT * FROM Orders WHERE StoreNumber = '$Store' AND Cancel = 'checked' AND Order_Type = 'Cash' AND Cancel_Date > '$Sevendaysback'");
    $tot_ord_ins_prt = mysql_num_rows($result_cash_canceled);


    if ($tot_ord_ins_prt !== 0){
        echo '<h4 class="blktext">Cancelled Orders for the store this week</h4><span class="blktext">';
        echo '<p><i>Fitter Action:  Fitter to contact client to notify of cancelled order, if not initialed by client.</i></p>';
        echo "<table border='4' class='rpttbl' frame='hsides' rules='rows' width='1400'>";
        echo '<tr><th>Store #</th><th>Order #</th><th>Customer</th><th>Phone #</th><th>Cancel Date</th width="150"><th>Reason for Cancellation</th><th width = "150">Patient Notified<th></tr>';
        while($row_cash_canceled = mysql_fetch_array($result_cash_canceled)){

            echo "<tr>";
            echo "<td align='center'>" . $row_cash_canceled['StoreNumber'] . "</td>";  
            echo "<td align='center'>" . $row_cash_canceled['Order_ID'] . "</td>";  
            echo "<td align='center'>" . $row_cash_canceled['Cust_First_Name'] . " " . $row_bo['Cust_Last_Name'] . "</td>";
            echo "<td align='center'>" . $row_cash_canceled['Cust_Phone'] . "</td>";
            echo "<td align='center'>" . $row_cash_canceled['Cancel_Date'] . "</td>"; 
            echo "<td align='center'>&nbsp;</td>";
            echo "<td align='left'>( ) Called: Patient Cancelled notified<br />( ) Called:  LVM for Patient</td>";
            echo "</tr>";
        }
        echo "</table>";
        echo "Total: " . $tot_ord_ins_prt;
        echo'</span>';
    }





    #Message at bottom of email
    echo '<br /><br /><br /><br /><p>Thank you for your prompt attention to this report.</p>';
    echo '<p>If this report is blank in all the above sections, this means, at this point, we are not showing any active orders within our system.<br />';                              
    echo 'If you feel this is in error, please contact our Customer Care team at:  <strong>(***) ***-8125</strong></p>';
    echo '<p>Please update this form with the appropriate action taken by patient, and fax back to: (866) 8**-****   OR email to: ******@*****.com</p>';
    echo '<p>Fitter Name: ________________________________________</p>';
    echo '<p>Comments:  _______________________________________________________________<br />';
    echo '_________________________________________________________________________</p>';
    echo '<p>The information contained in this email, together with any attachments, is intended only for the use of the individual or entity<br /> to which it is addressed. It may contain information that is confidential and prohibited from disclosure. If you are not the intended <br />';
    echo 'recipient, you are hereby notified that any dissemination, or copying, of this message or any attachment is strictly prohibited.</br> If you have received this message<br /> in error, please notify the original sender immediately by phone or by return email, </br>';
    echo 'and delete this email, along with any attachments. <br />Receipt by anyone other than the intended recipient is not</br> a waiver of any privileged information. </p>'; 

}

$body=ob_get_contents(); 
ob_end_clean(); 

#$body = "** It is Imperative that you respond to this email. When you receive this please print it out, sign your name and store number and fax the form to ***-***-1161**<br /><br /><br />";
#$body .= "Name: <br /><br />Store #:";


$headers = 'From: Visual Footcare Technologies *****@****.com'.$eol; 
$headers .= 'Reply-To: Visual Footcare Technologies *****@*****.com'.$eol; 
$headers .= 'Return-Path: Visual Footcare Technologies <mcooper@visualfootcare.com>'.$eol;     // these two to set reply address 
#$headers .= 'Cc: ******@*****.com'.$eol;
$headers .= "Message-ID:<".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol; 
$headers .= "X-Mailer: PHP v".phpversion().$eol;           // These two to help avoid spam-filters 

$mime_boundary=md5(time()); 
$headers .= 'MIME-Version: 1.0'.$eol; 
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol; 
$msg = ""; 


$msg .= "Content-Type: multipart/alternative".$eol; 

$msg .= "--".$mime_boundary.$eol; 
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol; 
$msg .= "Content-Transfer-Encoding: 8bit".$eol; 
$msg .= $body.$eol.$eol; 

$msg .= "--".$mime_boundary."--".$eol.$eol;   // finish with two eol's for better security. see Injection. 

然后是标准邮件(......)代码,用于发送电子邮件然后结束循环。

希望这是有道理的。

2 个答案:

答案 0 :(得分:0)

尝试更改此

if ($tot_ord_ins_prt !== 0)

if ($tot_ord_ins_prt !== false)

答案 1 :(得分:0)

MIME标题栏必须以空行终止,即使在多部分部分中使用也是如此。我不知道你的意思是&#34;随意&#34;但我怀疑&#34;空白的电子邮件&#34;可能是您的邮件正文被解释为无效MIME标头的结果。

在最后一个MIME标头和邮件正文之间插入一个空行:

$msg .= $eol.$body.$eol.$eol; 

如果这没有帮助,你应该表明&#34;标准&#34;你提到的mail行。由于它是实际发送电子邮件的那个,我很惊讶您没有包含它。你包括了很多其他代码。很高兴看到你对两个字符串$headers$msg做了什么。