AndieB Posted January 8, 2009 Share Posted January 8, 2009 Hi all, I have a script that will send an e-mail using the mail() function in PHP. I have already created variables containing to, subject and headers, and it looks so far like this: mail($to, $subject, , $headers); As you can see, the message is not yet on place. This is were I need help. I have created a HTML formatted text file, with the extension .PHP, that shall be used as the message. I tried the following: mail($to, $subject, include("lang/email.eng.php"), $headers); The result was, that the file was displayed on the screen and the e-mail sent contained in the body text only number 1 (one). I guess that the include function returned it was successfull, TRUE or 1 (one). Now, HOW do I do to include the email.eng.php file so it is interpeted as the "message" used by the mail() function? Thankful for any kind of help! Sincerely, Andreas Quote Link to comment https://forums.phpfreaks.com/topic/140077-solved-mail-function-include-message-file/ Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 If there is no PHP in the text file, just text then use this instead: mail($to, $subject, file_get_contents("lang/email.eng.php"), $headers); file_get_contents Quote Link to comment https://forums.phpfreaks.com/topic/140077-solved-mail-function-include-message-file/#findComment-732864 Share on other sites More sharing options...
AndieB Posted January 8, 2009 Author Share Posted January 8, 2009 Hi and thank you for a speedy answer! Well, the thing is that there is PHP code in the email.eng.php file. It looks kind of like this: <html> <head> <title>INFORMATION</title> </head> <body> <p >Hello <?php echo $_SESSION["firstname"] . " " . $_SESSION["lastname"]; ?> ,</p> ... The $headers contain information to say the e-mail well be sent as HTML. So, as you can see, there is some work to do with the email.eng.php file for PHP first, before sending it away... Any idea HOW I should do it to make it work as I want to? Sincerely, Andreas Quote Link to comment https://forums.phpfreaks.com/topic/140077-solved-mail-function-include-message-file/#findComment-732868 Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 I would change that php file into a heredoc version, then just call $message, here is an example: <?php $message = <<<MESSAGE <html> <head> <title>INFORMATION</title> </head> <body> <p >Hello {$_SESSION['firstname']} {$_SESSION['lastname']},</p> ... MESSAGE; ?> Then the mail example would be: include("lang/email.eng.php"); mail($to, $subject, $message, $headers); Quote Link to comment https://forums.phpfreaks.com/topic/140077-solved-mail-function-include-message-file/#findComment-732875 Share on other sites More sharing options...
AndieB Posted January 8, 2009 Author Share Posted January 8, 2009 It was THE solution for me!! Many many thanks premiso!! Sincerely, Andreas Quote Link to comment https://forums.phpfreaks.com/topic/140077-solved-mail-function-include-message-file/#findComment-732881 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.