Jump to content

[SOLVED] mail() function include message file


AndieB

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.