简体   繁体   中英

how to include PHP script as body of email

I have a php script that makes some MySQL queries that just writes some HTML (with the dynamic data) to a page. What I want to do is send an email with this HTML as the body. Lets say that the HTML code that I want to insert into the body of the email is contained in my_html_script.php , and I want to send it 2 $_GET parameters as well to make the dynamic content come out correctly.

I am in the Joomla framework, so the code to send the email looks like this:

$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.";
}

So, basically I need to include the HTML output of my_html_script.php into the $body string variable. How do I do this?

Thanks!

You would just declare the variables before this block and use:

ob_start();
include ('my_html_script.php');
$body = ob_get_clean();

你可以这样做:

$body = file_get_contents("http://example.com/my_html_script.php?getvar=foo&othervar=bar");

I think you need this, but...

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

You can send http request with params: param1, param2 or any other.

$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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM