¿Cómo enviar una consulta a una página php y obtener datos html en 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.

por ejemplo.

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.

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?.

preguntado el 23 de abril de 13 a las 11:04

What do you mean "send query to the page"? You can have a form in which the user inserts his text and make email_processor.php page get this form (<form action="email_processor.php ...>. -

is email_processor.php on your own site? -

the email_proccessor.php is in my site -

3 Respuestas

You can require your email_processor.php:

$body = require 'email_processor.php';

In this case you must return some body in your email_processor.php

Another case: you can use output buffer:

require 'email_processor.php';
$body = ob_get_clean();

In this case you must echo some body in your email_processor.php

Respondido 23 Abr '13, 11:04

Utilice las 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);

Respondido 23 Abr '13, 11:04

this does not work, thanks for your attempt. is there another way? - sirlouis

@slb what is not work? I am using same code for my work and it is working perfectly. - Yogesh Suthar

@slb did you change the $data in curl_setopt($ch, CURLOPT_POSTFIELDS,$data); to the correct data you wanted to post? - Jon

please can you show me how to format the data. lets say i want to send $data='id=66&new=po'. and the email_processor.php is has something like if(isset($_POST['id'])){ $id=$_POST['id']; // continue to process } - sirlouis

some OS will only read it when you pass it like this:

$body = file_get_contents('./email_processor.php');

Respondido 23 Abr '13, 11:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.