file_get_contents stylee with PHP parsing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aetherweb

    file_get_contents stylee with PHP parsing

    This is probably really obvious, sorry, been a long day...

    I'm wanting to create a PHP file which is a template for an email, and
    read the file into a string, ready to send out using my email
    functions... but I want to be able to get the PHP file to be server
    processed so that its content is created on the fly.

    Eg in pseudo code, what I want to do is this:

    1$email_param1 = "my email param 1";
    2$email_param2 = "my email param 2";
    3etc

    4$email_content = file_get_conten ts("email.php") ;

    5mySendMail("To @somewhere.com" ,"From@somewher eelse.com","My Email
    Subject", $email_content) ;

    Where "email.php" changes depending upon the content of the
    email_param variables.

    I could change line 4 to something like this:

    $email_content = file_get_conten ts("email.php?p aram1=my+email+ param
    +1&param2=my+em ail+param+2");

    ?

    Thanks,

  • ZeldorBlat

    #2
    Re: file_get_conten ts stylee with PHP parsing

    On Mar 21, 11:02 am, "Aetherweb" <jeffs...@gmail .comwrote:
    This is probably really obvious, sorry, been a long day...
    >
    I'm wanting to create a PHP file which is a template for an email, and
    read the file into a string, ready to send out using my email
    functions... but I want to be able to get the PHP file to be server
    processed so that its content is created on the fly.
    >
    Eg in pseudo code, what I want to do is this:
    >
    1$email_param1 = "my email param 1";
    2$email_param2 = "my email param 2";
    3etc
    >
    4$email_content = file_get_conten ts("email.php") ;
    >
    5mySendMail("T. ..@somewhere.co m","F...@somewh ereelse.com","M y Email
    Subject", $email_content) ;
    >
    Where "email.php" changes depending upon the content of the
    email_param variables.
    >
    I could change line 4 to something like this:
    >
    $email_content = file_get_conten ts("email.php?p aram1=my+email+ param
    +1&param2=my+em ail+param+2");
    >
    ?
    >
    Thanks,
    If the file is local file_get_conten ts() will do just that -- get the
    contents of the file. If you want it to be parsed through PHP then
    you need to request it as though you were requesting a webpage:

    $email_content = file_get_conten ts("http://wwww.myserver.c om/email.php?
    param1=my+email +param+1&param2 =my+email+param +2");

    Comment

    • Aetherweb

      #3
      Re: file_get_conten ts stylee with PHP parsing

      This is probably really obvious, sorry, been a long day...
      >
      I'm wanting to create a PHP file which is a template for an email, and
      read the file into a string, ready to send out using my email
      functions... but I want to be able to get the PHP file to be server
      processed so that its content is created on the fly.
      >
      Eg in pseudo code, what I want to do is this:
      >
      1$email_param1 = "my email param 1";
      2$email_param2 = "my email param 2";
      3etc
      >
      4$email_content = file_get_conten ts("email.php") ;
      >
      5mySendMail("T. ..@somewhere.co m","F...@somewh ereelse.com","M y Email
      Subject", $email_content) ;
      >
      Where "email.php" changes depending upon the content of the
      email_param variables.
      >
      I could change line 4 to something like this:
      >
      $email_content = file_get_conten ts("email.php?p aram1=my+email+ param
      +1&param2=my+em ail+param+2");
      >
      ?
      >
      Thanks,
      >
      If the file is local file_get_conten ts() will do just that -- get the
      contents of the file. If you want it to be parsed through PHP then
      you need to request it as though you were requesting a webpage:
      >
      $email_content = file_get_conten ts("http://wwww.myserver.c om/email.php?
      param1=my+email +param+1&param2 =my+email+param +2");
      Of course! Thank you. Knew I was being a retard.

      Comment

      • Toby A Inkster

        #4
        Re: file_get_conten ts stylee with PHP parsing

        ZeldorBlat wrote:
        $email_content = file_get_conten ts("http://wwww.myserver.c om/email.php?
        param1=my+email +param+1&param2 =my+email+param +2");
        This causes a subrequest though, increasing server load and wasting time.
        You might find it better to do:

        $email_param1 = "my email param 1";
        $email_param2 = "my email param 2";
        ob_start();
        include 'email.php';
        $email_content = ob_get_clean();

        --
        Toby A Inkster BSc (Hons) ARCS
        Contact Me ~ http://tobyinkster.co.uk/contact
        Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

        * = I'm getting there!

        Comment

        • Jerry Stuckle

          #5
          Re: file_get_conten ts stylee with PHP parsing

          Aetherweb wrote:
          This is probably really obvious, sorry, been a long day...
          >
          I'm wanting to create a PHP file which is a template for an email, and
          read the file into a string, ready to send out using my email
          functions... but I want to be able to get the PHP file to be server
          processed so that its content is created on the fly.
          >
          Eg in pseudo code, what I want to do is this:
          >
          1$email_param1 = "my email param 1";
          2$email_param2 = "my email param 2";
          3etc
          >
          4$email_content = file_get_conten ts("email.php") ;
          >
          5mySendMail("To @somewhere.com" ,"From@somewher eelse.com","My Email
          Subject", $email_content) ;
          >
          Where "email.php" changes depending upon the content of the
          email_param variables.
          >
          I could change line 4 to something like this:
          >
          $email_content = file_get_conten ts("email.php?p aram1=my+email+ param
          +1&param2=my+em ail+param+2");
          >
          ?
          >
          Thanks,
          >
          Alternatively - put all of your contents in one file, each with it's own
          function, i.e.

          function emailtext1 ($param1, $param2) {
          $str = ... // Build one message here
          return $str;
          }

          function emailtext2 ($param1, $param2) {
          $str = ... // Build another message here
          return $str;
          }

          switch ($emailparm) {
          case 'content1':
          $email_content = emailtext1($ema il_param11, $email_param2);
          break;
          case 'content1':
          $email_content = emailtext2($ema il_param11, $email_param2);
          break;
          }

          Or, if you are just including one file - you just need one function and
          send it your params.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          Working...