ok im kind of going around in circles, what i want to do is simple. I have a web page which pulls information from an API into an object, iterates through various objects and displays the information in simple html tables.
Now this info displays as expected when i load the page. There is a lot of content in it.
What i want to do is setup a cron job to send a daily report via email based on this php page. With standard HTML it seems to work fine, when i use dynamic php code it seems to mess things up.
Originally i tried with standard php mail, this was just displaying the source code, someone suggested using file_get_contents with phpmailer and thats where im at now but im a little out of my depth. Is there some sort of escaping or encoding/decoding i should be doing, the whole idea was i wouldnt have to escape the code line by line so i hope not :(
Here is a snippet of the code im running:
<body>
<?php
$username = '[email protected]';
$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>
Now if i load the page i see:
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
But if i run this:
<?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 = "[email protected]"; // GMAIL username
$mail->Password = "xxx"; // GMAIL password
$mail->SetFrom('[email protected]', 'First Last');
$mail->AddReplyTo("[email protected]","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 = "[email protected]";
$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!";
}
?>
Then this is the output i see when the email arrives is:
issues; ?>
Table 1
fields->issuetype->iconUrl; ?>
I just want the email to show exactly what i see in the browser when loading the page. Is there an easy way to do this, tried searching but finding it hard to describe what im looking to do as i dont know if its possible with phpmailer or if i need encoding etc?