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.
use of include() in $message
Moderators: Chris Corbyn, General Moderators
Re: use of include() in $message
Don't use include for non-php files. use file_get_contents() instead
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: use of include() in $message
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.
In your case, use file_get_contents() as previously suggested however.
Re: use of include() in $message
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
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
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: use of include() in $message
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).