以下是功能完整的代码。当我通过浏览器调用它时,它可以工作。但是,我无法让我的Cron工作来运行它。我试图想出任何解决方案,并且愿意接受任何想法,这些脚本可以每小时24小时全天候启动一次。邮件脚本需要每小时运行一次,但cron不能正常工作
信息:
- HostGator的
- PHP 5.4
- 链接,HostGator的克龙命令:http://support.hostgator.com/articles/cpanel/what-do-i-put-for-the-cron-job-command?utm_source=cPanel&utm_medium=message&utm_campaign=Cron%20Jobs
我曾尝试以下:
在做这些我的尚未向数据库添加销售或发送一封电子邮件:
/opt/php54/bin/php /home1/user/public_html/Sales/scripts/sales-notif_em.php
- 无法打开输入文件:/home1/user/public_html/scripts/sales-notif_em.phpphp /home1/user/public_html/Sales/scripts/sales-notif_em.php
- 空白电子邮件什么也没有,但这显示:内容类型:text/html的php -q /home1/lotscav1/public_html/Sales/scripts/sales_notif_em.php
- 我不明白当然/usr/bin/curl home1/user/public_html/scripts/sales-notif_em.php
从系统中的任何电子邮件 - 卷曲:(3)畸形- 任何命令(如PHP或/ usr/bin中/卷曲)具有下半年http://website.c0m/Sales/scripts/sales_notif_em.php - 尝试添加Cron时会导致JSON错误工作
我已经检查了以下几件事:
- 文件的权限是655
- 时间戳是不到一个小时的老客户表
这下我的代码:
<?php
//find out current time and 1 hour ago
date_default_timezone_set('America/New_York');
$current_time = strtotime("now");
$hour_ago = strtotime('-1 hour');
//////////////////////////////////////////////////////////////////
/////////////////l// Connect to Sales Database ///////////////////
//////////////////////////////////////////////////////////////////
$mysqli_s = new mysqli("localhost", "user", "password",
"server_sales_data");
if ($mysqli_s->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli_s->connect_errno . ")
" . $mysqli_s->connect_error;
}
//////////////////////////////////////////////////////////////////
///////////////////// Connect to EM Database ////////////////////
//////////////////////////////////////////////////////////////////
$mysqli_em = new mysqli("localhost", "user", "password",
"server_dlgEM");
if ($mysqli_em->connect_errno) {
echo "Failed to connect to MySQL_EM: (" . $mysqli_em->connect_errno .
") " . $mysqli_em->connect_error;
}
//Grab store name
$dlg_store = "EM";
$em_request = "SELECT * FROM customers WHERE date BETWEEN '$hour_ago'
AND '$current_time'";
$em_result = mysqli_query($mysqli_em, $em_request) or die("Error No
Sales EM");
while ($em_row = mysqli_fetch_array($em_result)) {
$em_prod_num = $em_row["prod_num"];
$em_receipt = $em_row["receipt"];
//////////////////////////////////////////////////////////////////
///////////////////// Grab info for EM Sales ////////////////////
//////////////////////////////////////////////////////////////////
$request_s = "SELECT * FROM all_products WHERE
dlgprod_num='$em_prod_num' AND dlg_store='$dlg_store'";
$result_s = mysqli_query($mysqli_s, $request_s) or die("Error dlg
prod num EM");
while ($row_s = mysqli_fetch_array($result_s)) {
$sku_s = $row_s["sku"];
$dlgprod_num_s = $row_s["dlgprod_num"];
$book_title_s = addslashes($row_s["book_title"]);
$dlgprod_price_s = $row_s["dlgprod_price"];
$author_name_s = addslashes($row_s["author_name"]);
$author_email_s = $row_s["author_email"];
$publisher_s = $row_s["publisher"];
$dlg_store_s = $row_s["dlg_store"];
$add_sql_s = "INSERT INTO all_author_sales SET
`sku`='$sku_s',
`dlgprod_num`='$dlgprod_num_s',
`dlgprod_nam`='$book_title_s',
`dlgprod_price`='$dlgprod_price_s',
`author_name`='$author_name_s',
`author_email`='$author_email_s',
`publisher`='$publisher_s',
`dlg_store`='$dlg_store_s',
`dlgcustomer_receipt`='$em_receipt' ";
//create signature
$sig = "The Admin Team at www.website.com";
//to
$admin_email = "[email protected]";
$to = array($author_email_s, $admin_email);
//setup email headers
$headers='From: ' . $admin_email . "\r\n" .
'Reply-To: ' . $admin_email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= $emailbody."\n\n";
//email subject and body
$subject = "Your book stats";
$message = "
Hi $author_name_s,<br />
I just wanted to send you a message and let you know that the book or
books below have just been purchased.<br /><br />
Store: $dlg_store_s<br />
Receipt: $em_receipt<br />
Sku Number: $sku_s<br /><br />
Book Title: $book_title_s<br />
Publisher: $publisher_s<br />
Product Number: $dlgprod_num_s<br />
Price: $dlgprod_price_s<br /><br />
Sincerely,<br />
$sig<br /><br />
To remove yourself from this notification, please send an email to
$admin_email with Unsubscribe in the subject line.
";
if ($mysqli_s->multi_query($add_sql_s) === TRUE) {
mail (implode(',', $to), $subject, $message, $headers);
} else {
echo "Error: " . $add_sql_s . "<br>" . $mysqli_s-
>error . "<br>" . $string;
}
}
}
?>
尝试在步骤工作到您的完整剧本,看看那里的错误所在。从一个新文件开始,简单地记录一些内容,然后做一个查询并记录下来......不断填充这些步骤,直到它出错为止,并且您将确切知道是什么导致了它。 – hdezela
谢谢!故障排除101 lol。我总是尝试过分复杂,先忘记简单的事情。 –
请花几分钟在这里尝试Markdown格式,特别是内联代码格式和无序列表(“项目符号”),因为它使事情变得更容易,更容易阅读,并减少志愿者编辑工作。谢谢。 (猜测,这可能是你的降薪的来源)。 – halfer