473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

php include() inside mail()

24
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $to = "someone2@example.com";
  3. $subject = "Test mail";
  4. $message = include("PROGRAMtoEXECUTE.html"); 
  5. $from = "someone1@example.com";
  6. $headers = "From: $from";
  7. mail($to,$subject,$message,$headers);
  8. echo "Mail Sent.";
  9. ?>
[Please use CODE tags when posting source code. Thanks! --pbmods]

This email contains a message which changes every time it is sent.
This changing message could be the time, some random numbers, etc..
Is there any way to have it run the program and then send the output?
May 28 '07 #1
2 1628
bergy
89
Yes, this is possible, however you don't want to use the include() function. Try using file_get_contents()

Your code would look like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $to = "someone2@example.com";
  3. $subject = "Test mail";
  4. $message = file_get_contents("PROGRAMtoEXECUTE.html"); 
  5. $from = "someone1@example.com";
  6. $headers = "From: $from";
  7. mail($to,$subject,$message,$headers);
  8. echo "Mail Sent.";
  9. ?>
I'm almost positive you can use this to get a file at a specific URL as well so if your file is a PHP file that you want to execute you can do a file_get_contents("http://www.mysite.com/php.php"); If that doesn't work, check out cURL on php.net and google. That should give you everything you'd need to know.


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $to = "someone2@example.com";
  3. $subject = "Test mail";
  4. $message = include("PROGRAMtoEXECUTE.html"); 
  5. $from = "someone1@example.com";
  6. $headers = "From: $from";
  7. mail($to,$subject,$message,$headers);
  8. echo "Mail Sent.";
  9. ?>
[Please use CODE tags when posting source code. Thanks! --pbmods]

This email contains a message which changes every time it is sent.
This changing message could be the time, some random numbers, etc..
Is there any way to have it run the program and then send the output?
May 28 '07 #2
jrsjrs
24
Thank you Bergy!

I tried using file_get_contents(), with the txt, html and php extensions,
but this only gets the text of the program source codes, and does
not execute or run the program first, and then output the results.
For example, Save these 3 lines as "date.php".

<html><head></head><body>
<?php print date("Y-m-d"); ?>
</body></html>

And put "date.php" into the $message.
If you then send the email, you will receive the above 3 lines of code
and not the output of running those 3 lines of code.

I want to email only the program output and not the source code.
Perhaps, I should be looking for a completely different method?
May 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: wEEdpEckEr | last post by:
Hi, here's the deal: I have a config.php file in which I have set a few var's, to use in the whole site. E.g.: $db_host = "localhost"; Then I also have a class, which is supposed to...
2
by: Kupo | last post by:
Hi, I'm currently writing website using php. My problem is, when I do: include("../../library/file.php"); // this is from e.g /level1/level2/something.php it works. However, when I use: ...
6
by: Tom | last post by:
I'm tying myself in knots trying to figure out variable scope with constants and include files. This is what I'm doing: A page (index.php) on my website includes a general purpose include file...
10
by: r6uji7 | last post by:
hello, i am new to PHP programming and wondered if u could help. lets say i have the following files: 1. error.php: that is routed to for all errors. this page should display proper and...
0
by: Wilk Teverbaugh | last post by:
I've got an include file inside each page throughout my site. Inside this include file I'm running server.execute to include other pages based on a condition (userID). The problem has two parts-...
5
by: Kouisawang | last post by:
Hello all, I have a question when I found the following code; -------------------------------------------------------------------------------------- #ifndef FOO_H #define FOO_H //some more...
11
by: McKirahan | last post by:
I am looking for feedback on an approach to using PHP. Below is a stripped down version of a Home page: "index.php". The content of the site is displayed in the middle of the page and is...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
8
by: travispennington | last post by:
To anyone that can assist me: I deeply appreciate your help!! I am developing an application with an outside vendor. The vendor has a very odd requirement. They need custom X-Headers added to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.