2

我有一个 php 脚本,它可以进行一些 MySQL 查询,这些查询只是将一些 HTML(带有动态数据)写入页面。我想要做的是发送一封以这个 HTML 为正文的电子邮件。假设我要插入到电子邮件正文中的 HTML 代码包含在 中my_html_script.php,我还想向它发送 2 个$_GET参数以使动态内容正确显示。

我在 Joomla 框架中,所以发送电子邮件的代码如下所示:

$mailer =& JFactory::getMailer();
$sender = $from_email;
$mailer->setSender($sender);

$email = explode(';',$email);
for ($i=0;$i<count($email);$i++){
    $mailer->addRecipient(trim($email[$i]));
}

$body   = "




";


$mailer->setSubject('This is the subject');
$mailer->setBody($body);

// Optional file attached
//$mailer->addAttachment();

$send =& $mailer->Send();
if ( $send !== true ) {
    //die($send->message);
    echo "<p>email FAILED".$recip."</p>";
} else {
    //mail sent
    echo "Emailed successfully.";
}

所以,基本上我需要将 HTML 输出包含my_html_script.php$body字符串变量中。我该怎么做呢?

谢谢!

4

4 回答 4

5

您只需在此块之前声明变量并使用:

ob_start();
include ('my_html_script.php');
$body = ob_get_clean();
于 2012-07-18T16:20:15.350 回答
3

你可以这样做:

$body = file_get_contents("http://example.com/my_html_script.php?getvar=foo&othervar=bar");
于 2012-07-18T16:19:15.097 回答
0

我想你需要这个,但是...

$body = file_get_contents("path_to_file.php?param1=content&param2=content");

您可以发送带有参数的 http 请求:param1、param2 或任何其他。

于 2012-07-18T16:21:05.783 回答
0
$filename_xml="E-factuur ".$factuurnummer.".xml";
ob_start();
$_GET['knr']=$klantnummer;
$_GET['bnr']=$bestelnummer;
$_GET['key']=$_SESSION['user_id'];
include("basisUBL_xml.php");//inside the above $_GET['..'] are parsed 
$content_xml = ob_get_clean();
$content_xml = chunk_split(base64_encode($content_xml));
$name_xml = basename($filename_xml);
$uid="=_Part_2408_".md5(uniqid(time()));
$logopad_emails="https://www.yourdomainhere.nl/images/logo.png";
$headerx="MIME-Version: 1.0\r\n";
$headerx.="From: webshop www.yourdomainhere.nl <info@yourdomainhere.nl>\r\n";
$headerx.="Reply-To: info@yourdomainhere.nl \r\n";
$headerx.="Errors-To: info@yourdomainhere.nl \r\n";
$headerx.="X-Mailer: yourdomainhere Mailscript \r\n";
$headerx.="Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
// message & attachment
$messagex = "--".$uid."\r\n";
$messagex .= "Content-type:text/html; charset=iso-8859-1\r\n\r\n"; //2x \r\n important for OXS email and iphone!!!
$messagex .= $htmlbody3."\r\n\r\n";
$messagex .= "--".$uid."\r\n";
$messagex .= "Content-Type: application/octet-stream; name=\"".$name_pdf."\"\r\n";
$messagex .= "Content-Transfer-Encoding: base64\r\n";
$messagex .= "Content-Disposition: attachment; filename=\"".$name_pdf."\"\r\n\r\n";
$messagex .= $content_pdf."\r\n\r\n";
$messagex .= "--".$uid."\r\n";
$messagex .= "Content-Type: application/octet-stream; name=\"".$name_xml."\"\r\n";
$messagex .= "Content-Transfer-Encoding: base64\r\n";
$messagex .= "Content-Disposition: attachment; filename=\"".$name_xml."\"\r\n\r\n";
$messagex .= $content_xml."\r\n\r\n";
$messagex .= "--".$uid."--";
$mailtox='info@yourdomainhere.nl';
$subjectx='UBL test'.$factuurnummer;
于 2018-04-30T17:45:28.270 回答