Page 1 of 1

include() not working with mail()

Posted: Tue Jan 18, 2011 5:31 pm
by fleabite08
Hey

I want to use the include() function in my mail() but when I send the PHP to HTML email, all I get in the content of my email is 1. Here is my basic code


Code: Select all

<?php

// includes HTML email prebuilt -textt.php
$text = include('text.php');

// multiple recipients
$to  = ' baba@baba.co' . ', '; // note the comma
$to .= ' baba@baba.co;

// subject
$subject = 'email test ';

// message
$message = ' $text';



// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: ' . "\r\n";
$headers .= 'From: baba@baba.com' . "\r\n";
$headers .= 'Cc: ' . "\r\n";
$headers .= 'Bcc: baba@baba.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);


?>
can any one please tell me why this is happening?

Thanks
Daniel

Re: include() not working with mail()

Posted: Tue Jan 18, 2011 5:36 pm
by Jonah Bron
If you look at the manual (http://php.net/include), you'll see that include() does not return the contents of that file. To do that, you'll need to use file_get_contents() instead (http://php.net/file-get-contents).

Re: include() not working with mail()

Posted: Tue Jan 18, 2011 6:35 pm
by Benjamin
:arrow: Moved to PHP - Code

Re: include() not working with mail()

Posted: Tue Jan 18, 2011 10:35 pm
by fleabite08
Thanks you I will try that tonight :)