OK、私はぐるぐる回っていますが、私がやりたいことは単純です。API からオブジェクトに情報を取得し、さまざまなオブジェクトを反復処理し、情報を単純な html テーブルに表示する Web ページがあります。
ページをロードすると、この情報が期待どおりに表示されるようになりました。その中にはたくさんのコンテンツがあります。
私がやりたいことは、この php ページに基づいて電子メールで日次レポートを送信する cron ジョブをセットアップすることです。標準の HTML では問題なく動作するようですが、動的な php コードを使用すると問題が発生するようです。
もともと私は標準のphpメールで試しましたが、これはソースコードを表示するだけでした。誰かがphpmailerでfile_get_contentsを使用することを提案しました。私がしなければならないある種のエスケープまたはエンコーディング/デコーディングはありますか、全体的なアイデアは、コードを1行ずつエスケープする必要がないので、そうしないことを願っています:(
実行中のコードのスニペットを次に示します。
<body>
<?php
$username = 'xxx@gmail.com';
$password = 'xxx';
$url ='xxx.atlassian.net/rest/api/2/search?jql=project+%3D+bug+AND+updated+%3C%3D+2d+AND+status+%3D+%22In+Beta%22+AND+assignee+!%3D+beta_merge+ORDER+BY+priority+DESC';
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$issue_list = curl_exec($curl);
$issue_json = json_decode($issue_list);
//var_dump($issue_json);
$bugs = $issue_json->issues;
?>
<h2>Table 1</h2>
<table cellspacing="0" cellpadding="3" width="80%">
<?php foreach ($bugs as $bug)
{?>
<tr>
<td><?php echo $bug->fields->issuetype->iconUrl; ?></td>
</tr>
<?php } ?>
</table>
ページをロードすると、次のように表示されます。
表1
http://www.xxx.com/images/bug_16.png
http://www.xxx.com/images/bug_16.png
http://www.xxx.com/images/feature_16.png
http://www.xxx.com/images/bug_16.png
しかし、これを実行すると:
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = file_get_contents('jira_filters.php');
//$body = preg_replace('/[\]/','',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "xxx@gmail.com"; // GMAIL username
$mail->Password = "xxx"; // GMAIL password
$mail->SetFrom('xxx@gmail.com', 'First Last');
$mail->AddReplyTo("xxx@gmail.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "xxx@him.net";
$mail->AddAddress($address, "John Doe");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
次に、これは、電子メールが到着したときに表示される出力です。
issues; ?>
Table 1
fields->issuetype->iconUrl; ?>
ページをロードするときにブラウザに表示される内容を正確にメールに表示したいだけです。これを行う簡単な方法はありますか?