這是我將發送電子郵件的 PHP 頁面代碼,但我無法提供資料庫連接檔案的路徑,如果我通過瀏覽器運行腳本,該檔案將完美運行。
編輯:我已經用包含和檔案目錄更新了代碼。現在正在更新其他錯誤截圖。
#!/usr/bin/php70
include __DIR__.'/db_connection.php';
include __DIR__.'/PHPMailer-master/PHPMailerAutoload.php';
/* Date time sent emails */
$date = new DateTime('now', new DateTimeZone('Asia/Karachi'));
$email_query = "SELECT *FROM marketing_email WHERE email_timer = '1' ";
$email_result = mysqli_query($db, $email_query);
if (mysqli_num_rows($email_result) > 0) {
while ($email_rows = mysqli_fetch_assoc($email_result)) {
$attechment_query = "SELECT *FROM marketing_email_attechements WHERE marketing_email_id = '".$email_rows['id']."' AND status = '1' ";
$attechment_result = mysqli_query($db, $attechment_query);
if ($attechment_result) {
$path = array();
while ($attechment_rows = mysqli_fetch_assoc($attechment_result)) {
$path[] = '../uploads/email-files/'.date('dmY').'-'.$attechment_rows['filename'];
}
}
// exit();
if ($date->format('Y-m-d H:i:00') >= $email_rows['email_datetime']) {
/* Send email */
$subject = $email_rows['subject'];
$msg = $email_rows['message'];
$to = $email_rows['receiver_email'];
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
$mail->Port = 587;
for($ct=0;$ct<count($path);$ct ){
$mail->AddAttachment($path[$ct]);
}
// $mail->AddAttachment($path);
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = '[email protected]';
//Password to use for SMTP authentication
$mail->Password = "abdullah999";
//Set who the message is to be sent from
$mail->From = '[email protected]';
$mail->FromName = 'Job-interview';
//Set an alternative reply-to address
//$mail->addReplyTo(‘[email protected]', 'hidaya');
//Set who the message is to be sent to
$mail->addAddress($to,'Job-interview');
//Set the subject line
$mail->Subject = $subject;
$mail->msgHTML($msg);
//send the message, check for errors
if (!$mail->send()) {
"Mailer Error: " . $mail->ErrorInfo;
//header("location:manage_users.php?flag=3");
}
else {
$update_query = "UPDATE marketing_email SET email_timer = '0' WHERE id = '".$email_rows['id']."' ";
$update_result = mysqli_query($db, $update_query);
}
}
else{
echo "time not exist";
}
}
?>
<script type="text/javascript">
//location.href="../email-list.php";
console.log('Thank you email has been sent');
</script>
<?php
}
else{
echo "Data not found";
}
?>
我正在嘗試為我創建的 cron 作業安排電子郵件,該作業給了我一個檔案錯誤,該錯誤在瀏覽器中運行良好。
這是我嘗試創建 cron 作業并測驗它的檔案是否運行時從我的 cpanel 截取的螢屏截圖。

uj5u.com熱心網友回復:
您可以將 cron 命令重命名為/usr/bin/php70 -f /path/to/your.php,并確保/usr/bin/php70路徑有效。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/330271.html
