php include() inside mail()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jrsjrs
    New Member
    • Sep 2006
    • 24

    php include() inside mail()

    [code=php]<?php
    $to = "someone2@examp le.com";
    $subject = "Test mail";
    $message = include("PROGRA MtoEXECUTE.html ");
    $from = "someone1@examp le.com";
    $headers = "From: $from";
    mail($to,$subje ct,$message,$he aders);
    echo "Mail Sent.";
    ?>[/code]

    [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?
    Last edited by pbmods; May 28 '07, 01:10 AM. Reason: Added code tags.
  • bergy
    New Member
    • Mar 2007
    • 89

    #2
    Yes, this is possible, however you don't want to use the include() function. Try using file_get_conten ts()

    Your code would look like this:
    [code=php]<?php
    $to = "someone2@examp le.com";
    $subject = "Test mail";
    $message = file_get_conten ts("PROGRAMtoEX ECUTE.html");
    $from = "someone1@examp le.com";
    $headers = "From: $from";
    mail($to,$subje ct,$message,$he aders);
    echo "Mail Sent.";
    ?>[/code]

    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_conten ts("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.


    Originally posted by jrsjrs
    [code=php]<?php
    $to = "someone2@examp le.com";
    $subject = "Test mail";
    $message = include("PROGRA MtoEXECUTE.html ");
    $from = "someone1@examp le.com";
    $headers = "From: $from";
    mail($to,$subje ct,$message,$he aders);
    echo "Mail Sent.";
    ?>[/code]

    [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?

    Comment

    • jrsjrs
      New Member
      • Sep 2006
      • 24

      #3
      Thank you Bergy!

      I tried using file_get_conten ts(), 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?

      Comment

      Working...