CRONジョブを使用して終わりの自動メールを設定しようとしています。CRON - PHP - file_get_contents CRONでPHPページと電子メールを実行する
静的な電子メールを送信するためにCRONジョブを取得できますが、file_get_contentsとPHPページを使用しようとすると問題が発生します.SQLページでは、mysqlクエリを使用してデータベースからデータを取得し、
ヘルプが必要です。 *注 - 私はSMTP用に特別なPHPメーラーを使用します。このメーラーは、静的な電子メールを送信したり、動的電子メールを手動で送信したり(CRONではなく)、100%FINEで動作します。 実際にPHPファイルにアクセスしてデータを取得するためにCRONジョブを取得することができません。
CRONによって運営されているメーラーファイル:
#!/usr/bin/php
<?php
set_include_path('/Library/WebServer/Documents/pbhsadmin/');
include '_classes/class.phpmailer.php';
$email = 'EMAIL';
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$mail->Subject = "PBHS Administration - Changes Department Daily Report";
$body = file_get_contents('http://localhost/pbhsadmin/_mail/changes_daily.php');
//$body = 'Testing no get file';
$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$mail->From = "[email protected]";
$mail->FromName = "PBHS Support";
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "mail.SERVER.com"; // SMTP server
$mail->Username = "EMAIL" // SMTP server username
$mail->Password = "PASSWORD"; // SMTP server password
$mail->IsSendmail(); // tell the class to use Sendmail
$mail->AddReplyTo("[email protected]","PBHS Support");
$mail->AddAddress($email);
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'message sent!';
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
?>
PHPページのデータベースを照会し、電子メールを作成するためにMySQLを使用して:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Changes Department - Daily Report</title>
</head>
<body>
<?PHP
set_include_path('/Library/WebServer/Documents/pbhsadmin/');
include 'SQL CONNECTION FILE';
$query = "QUERY";
$result = mysql_query($query)or die(mysql_error());
while($row=mysql_fetch_array($result)){
if($row['userid']==0)
$username = 'Unassigned';
else
$username = $row['username'];
$userid = $row['userid'];
//GET ALL PROJECTS WORKED ON FOR THIS USER
$query2 = "QUERY";
$result2 = mysql_query($query2)or die(mysql_error());
echo '
<div class="employee">
<h1>'.$username.'</h1>
<table><tr><th>Site</th><th>Hours Worked</th><th>Total Hours</th><th>Status</th></tr>';
while($row2=mysql_fetch_array($result2)){
$domain = $row2['domain'];
$hours = $row2['hours'];
if($row2['completed']!='0000-00-00 00:00:00')
$status = 'Completed';
else
$status = 'Incomplete';
$total_hours = $row2['act_hours'];
echo '<tr><td class="center">'.$domain.'</td><td class="center">'.$hours.'</td><td class="center">'.$total_hours.'</td><td class="center '.$status.'">'.$status.'</td></tr>';
}
if(mysql_num_rows($result2)==0)
echo '<tr><td colspan="4" style="text-align:center;"><i>No Projects Worked On</i></td></tr>';
echo '</table></div>';
}
?>
</body>
</html>
$ mail-> Username = "EMAIL'あなたがdisplay_errorsをオフにしている場合、この問題が起こっているかどうかはわかりませんが、これは非常にうまくいくかもしれませんあなたの問題の原因になります。 – mfonda
それは私の安全な情報を編集しただけの結果でした。この問題はメーラーファイルにはまったく関連していません。 $ body =を文字列(つまり$ body = 'testing')に変更した場合、電子メールは正しく送信されます。これはfile_get_contentsと関係があります。私は、CRONジョブがサーバ上のphpファイルを実際に処理する方法や方法について何かを考えています。 – JimmyJammed