以下是功能完整的代碼。當我通過瀏覽器調用它時,它可以工作。但是,我無法讓我的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