* .bat文件有竅門。並通過任務計劃程序將其踢出。最初我有bat文件指向不正確的目錄,這就是爲什麼一些功能無法正常工作。我的下一步是清理我的代碼,並使用base64和html來美化郵件。
php C:\Apache_Directory\htdocs\my_phpscript.php
我的劇本......是的,我知道這是不是很乾淨/完美,它仍然有大量的工作,但現在它在做什麼,我需要做的:
<?php
$sql1 = "USE database_name";
$sql2 = "TRUNCATE TABLE my_table";
$sql3 = "LOAD DATA LOCAL INFILE 'DataImport//import_file.csv'
REPLACE INTO TABLE my_table
CHARACTER SET latin1
FIELDS TERMINATED BY ','
IGNORE 1 LINES
(`record_number`
, `module_name`
, `action_date`
, `location`
, `type_of_outlet`
, `user_name`
, `store_code`
, `outlet_name`
, `line_question`
, `line_field_id`
, `line_value`
, `brand_code`
, `brand`);";
/* $sql4 = "SELECT COUNT(creation_time) FROM my_table
WHERE DATE(creation_time) = DATE_SUB(CURRENT_DATE(), INTERVAL 0 DAY)"; */
$con=mysqli_connect("localhost","root","mysqlpassword","database");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
};
$result1 = mysqli_query($con, $sql1);
$result2 = mysqli_query($con, $sql2);
$result3 = mysqli_query($con, $sql3);
if (mysqli_affected_rows($con) > 1) {
$message ="". mysqli_affected_rows($con). " rows were successfully added to the my_table table!";
} else {
$message = "" . mysqli_error($con). "has caused the update to fail";
};
echo $message;
// To send HTML mail, the Content-type header must be set
require("PHPMailerAutoload.php"); // path to the PHPMailerAutoload.php file.
require("class.phpmailer.php");
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Name1 <[email protected]>, Name2<[email protected]>' . "\r\n";
$headers .= 'From: Report Server <[email protected]>' . "\r\n";
$subject = 'Data Import Resultt' ."\r\n";
$mail = new PHPMailer();
$mail->IsSMTP(true);
$mail->Mailer = "smtp";
$mail->Host = "smtp.host.co.za";
$mail->Port = 587; // 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->CharSet = "UTF-8";
$mail->SMTPOptions = array( // Bypass security verification on e-mail. WARNING: When using this method,
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->From = '[email protected]';
$mail->FromName = 'Reports Server';
$mail->AddAddress('[email protected]', 'Name1');
$mail->AddAddress('[email protected]', 'Name2');
$mail->AddAddress('[email protected]', 'Name3');
$mail->Subject = $subject;
$mail->Body = $message."\r\n";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
exit;
} else {
echo 'Message has been sent.';
}
mysqli_close($con);
?>
FreeBSD/Linux用戶在這裏。對Windows沒有想法,我也不知道你的PHP是如何編碼的,但是如果你可以從命令行運行PHP,你的方法是正確的。或者,如果您可以使用'curl','wget'或'fetch'命令從命令行「調用」網頁,則可以調度該命令。 – Tigger
在unix系統中,你可以做cronjobs,也許你可以在Windows?用AT命令 –