2013-12-09 55 views
0

我做了一个电子邮件脚本来邮寄由php查询提交的表格。它的作品,但我每次收到超过20倍的同一封电子邮件。但我根本找不到一个循环。谁能帮我?PHP脚本得到一个循环

<?php 

require_once("view_orders.php"); 

$to = 'mymail'; 
$subject = 'Broodje bestelling'; 

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

// Put your HTML here 
$message = file_get_contents('http://myurl.com/order/mail.php', true); 

// Mail it 
return mail($to, $subject, $message, $headers); 
?> 
+3

它是如何被调用的? –

+4

你是怎么称呼这个脚本的? – qwertynl

+0

你为什么做:返回邮件($ to,$ subject,$ message,$ headers); ? – sergio

回答

2

那里没有循环。

根据你的文件设置的方式,我的直觉是你多次调用这个文件。你有任何要求/包括链接回这个文件?深入挖掘。任何时候你找到一个参考,按照它,从view_orders.php开始。

另外要注意的 - 它可能会更好,如果你做出这样的功能,然后调用函数,就像这样:

require_once(“view_orders.php”);

function send_this_email() 
{ 
    $to = 'mymail'; 
    $subject = 'Broodje bestelling'; 

    // To send HTML mail, the Content-type header must be set 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

    // Put your HTML here 
    $message = file_get_contents('http://myurl.com/order/mail.php', true); 

    // Mail it 
    mail($to, $subject, $message, $headers); 
} 

以这种方式调试和引用功能要容易得多。从现在起,如果你这样做,你只需包含这个文件,然后执行功能send_this_email();

这是一个很小的改变,但通过将脚本放入函数和调用函数中,您的组织方式会比现在好得多。它会为你节省很多时间!

+0

已经知道了。谢谢 – sth313