Is there a way to embed code into $message?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Is there a way to embed code into $message?

Post 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]
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

So you want to send bodyCode.inc with the message?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

put it in a file and then you can for example: http://www.php.net/manual/en/function.f ... ntents.php
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

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

echo $file;
?>
is the best way in my opinion
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post 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);
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I would look into [php_man]regex[/php_man] and place the parsed text into the code
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

[php_man]fopen[/php_man],[php_man]fwrite[/php_man],[php_man]fclose[/php_man]
Post Reply