Page 1 of 1

Is there a way to embed code into $message?

Posted: Tue Aug 17, 2004 11:18 am
by ljCharlie
I'm trying to send an email using PHP. Below is my code:
$Email = fromEmail@myDomain.com;
$To = "myEmail@myDomain.com";
$message = '
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
This is only a test.
</body>
</html>'
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: '".$Email."'\r\n";
$subject = "It doesn't work";
mail($To, $subject, $message, $headers);
And the above code will work. Now here's what I want. I want to somehow embed the code:
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
This is only a test.
</body>
</html>
into a .inc file or some other compatible file so I can do something like this:

$message = require("bodyCode.inc");

if it is possible. Is there a way to embed into the $message so I don't have show all the html code?

ljCharlie[/b]

Posted: Tue Aug 17, 2004 11:25 am
by evilmonkey
So you want to send bodyCode.inc with the message?

Posted: Tue Aug 17, 2004 11:26 am
by AVATAr
put it in a file and then you can for example: http://www.php.net/manual/en/function.f ... ntents.php

Posted: Tue Aug 17, 2004 11:40 am
by ljCharlie
Yes. The body is html code because I want the email to be a html email format and not just plain texts. But the codes are too long and so I like to know if there is a better way to call the code back into the $message.

ljCharlie

Posted: Tue Aug 17, 2004 11:52 am
by John Cartwright

Code: Select all

<?
$file = file_get_contents("path/to/file");

echo $file;
?>
is the best way in my opinion

Posted: Tue Aug 17, 2004 11:56 am
by AVATAr
Phenom wrote:

Code: Select all

<?
$file = file_get_contents("path/to/file");

echo $file;
?>
is the best way in my opinion
using the examples...

Code: Select all

<?php
$Email = fromEmail@myDomain.com;
$To = "myEmail@myDomain.com";
$message =  file_get_contents("path/to/file"); //<--- here
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: '".$Email."'\r\n";
$subject = "It doesn't work";
mail($To, $subject, $message, $headers);
?>

Posted: Tue Aug 17, 2004 12:05 pm
by John Cartwright
I would look into [php_man]regex[/php_man] and place the parsed text into the code

Posted: Tue Aug 17, 2004 12:17 pm
by ljCharlie
Many many thanks for your help but here is what I got when I used file_get_contents("filename.inc"). The error is: Fatal error: Call to undefined function: file_get_contents()

What is that mean? The reason I didn't specify a path is because the filename.inc is located on the main direcotry of the website.

ljCharlie

Posted: Tue Aug 17, 2004 12:32 pm
by ljCharlie
I think I know wha that error means. I the PHP version that we have is only 4.0.6. What are my options then?

ljCharlie

Posted: Tue Aug 17, 2004 1:10 pm
by John Cartwright
[php_man]fopen[/php_man],[php_man]fwrite[/php_man],[php_man]fclose[/php_man]