Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
phpmailer文件\u获取\u内容和动态php代码_Php_Encoding_File Get Contents_Phpmailer - Fatal编程技术网

phpmailer文件\u获取\u内容和动态php代码

phpmailer文件\u获取\u内容和动态php代码,php,encoding,file-get-contents,phpmailer,Php,Encoding,File Get Contents,Phpmailer,好吧,我有点绕圈子,我想做的很简单。我有一个网页,它将API中的信息提取到一个对象中,遍历各种对象,并在简单的html表中显示信息 现在,当我加载页面时,此信息将按预期显示。里面有很多内容 我想做的是设置一个cron作业,根据这个php页面通过电子邮件发送每日报告。对于标准HTML,它似乎工作得很好,当我使用动态php代码时,它似乎会把事情搞砸 最初我尝试使用标准的php邮件,这只是显示源代码,有人建议使用phpmailer的file_get_内容,这就是我现在的位置,但我有点不了解。我是否应该

好吧,我有点绕圈子,我想做的很简单。我有一个网页,它将API中的信息提取到一个对象中,遍历各种对象,并在简单的html表中显示信息

现在,当我加载页面时,此信息将按预期显示。里面有很多内容

我想做的是设置一个cron作业,根据这个php页面通过电子邮件发送每日报告。对于标准HTML,它似乎工作得很好,当我使用动态php代码时,它似乎会把事情搞砸

最初我尝试使用标准的php邮件,这只是显示源代码,有人建议使用phpmailer的file_get_内容,这就是我现在的位置,但我有点不了解。我是否应该进行某种转义或编码/解码,整个想法是我不必逐行转义代码,所以我希望不会:(

以下是我正在运行的代码片段:

<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>
但如果我运行这个:

<?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!";
}

?>

我只是想让邮件准确地显示我在加载页面时在浏览器中看到的内容。有没有简单的方法可以做到这一点,尝试过搜索,但发现很难描述我想做什么,因为我不知道是否可以使用phpmailer或是否需要编码等?

您没有运行文件,只是从字面上获取文件的内容和内容将它们放置为电子邮件正文

请尝试以下方法:

ob_start();
include 'jira_filters.php'; //execute the file as php
$body = ob_get_clean();
ob_start()
生成所有正常的回音和直接的html、文本等(非

issues; ?> 

Table 1

fields->issuetype->iconUrl; ?>
ob_start();
include 'jira_filters.php'; //execute the file as php
$body = ob_get_clean();