[英]How to send query to a php page and get html data in php?
I am trying to send a html email from a php class in which the data is determined by the data sent to the class's method. 我正在尝试从php类发送一封html电子邮件,其中数据由发送到类的方法的数据确定。
for example. 例如。
public function send_warning_email($user_id, $email){
global $mail;
$body = file_get_contents('email_processor.php');
/// ohter codes
}
In above example. 在上面的例子中。 I want to send query to the email_processor.php page and get the return plain text and assign it to the $body variable. 我想将查询发送到email_processor.php页面并获取返回纯文本并将其分配给$ body变量。
Is there another function I can use instead of file_get_contents() that will allow me to send query to the php page and get return text or another approach to performing this task?. 是否有我可以使用的另一个函数而不是file_get_contents(),它将允许我向php页面发送查询并获得返回文本或执行此任务的其他方法?
You can require your email_processor.php: 您可以要求使用email_processor.php:
$body = require 'email_processor.php';
In this case you must return
some body in your email_processor.php
在这种情况下,您必须在email_processor.php
return
一些正文
Another case: you can use output buffer: 另一种情况:你可以使用输出缓冲区:
ob_start();
require 'email_processor.php';
$body = ob_get_clean();
In this case you must echo some body in your email_processor.php
在这种情况下,您必须在email_processor.php
回显一些正文
Use CURL
使用CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'email_processor.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
某些操作系统只会在你传递它时读取它:
$body = file_get_contents('./email_processor.php');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.