Page 1 of 1

use of include() in $message

Posted: Mon Jul 07, 2008 7:25 am
by meddiecap
Hi,

I was wondering if it were possible to use include files for sending emails, kind of hard to explain, but what I mean is e.g.:
$message->attach(new Swift_Message_Part(include('mail.hmtl'));


I tried it before but I get an error, e.g., if I have to following:
$message->attach(new Swift_Message_Part(include('mail_text.hmtl'); *
$message->attach(new Swift_Message_Part(include('mail_html.hmtl', "text/html"));

When I try this I get an error that there's an unexpected ';' near *. When I remove it, I get
unexpected T_VARIABLE error on the same line.

Does this mean include are not possible the way I want it, or am I not seeing something.

Re: use of include() in $message

Posted: Mon Jul 07, 2008 7:47 am
by Eran
Don't use include for non-php files. use file_get_contents() instead

Re: use of include() in $message

Posted: Wed Jul 09, 2008 2:38 am
by Chris Corbyn
You may use include() for non-PHP file extensions if they do indeed contain PHP code, but it's not advised.

In your case, use file_get_contents() as previously suggested however.

Re: use of include() in $message

Posted: Mon Jul 14, 2008 3:18 am
by meddiecap
I tried that, and it works in some way...

I want to send a plain mail and a HTML mail. When I include the message, so that the plain mail and html mail are located in a file that I include as follows (for both html & plain mail):

$message->attach(new Swift_Message_Part(include('mail_html.html'); <-- btw, what is the appropriate extension for plain and html messages? (or get_file_contents() for that matter)

What happens is that the message shows on screen when I send the mail. I solved this by not using includes after all. Still, I do wonder why this happens, because I think in my case it's more convenient to use includes.

So, maybe if someone can give me an example, I can try it again.

If i'm being unclear I can post the source code if I need to.

Ty

Re: use of include() in $message

Posted: Thu Jul 17, 2008 10:00 pm
by Chris Corbyn
include() is for loading PHP code into a script, not for loading static content. It will also output anything which the included script outputs. PHP was trying to parse the code which caused an error. file_get_contents() on the other hand is for reading the contents of a file and returning the string (it doesn't output anything).