using same script in email handling and POST web form

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

    using same script in email handling and POST web form

    Hi All, I have a script sitting on my web server called
    auto_mail.php5. I would like this to be used two different ways.

    One way would be for a web form to call it as submit action on a form.
    I have got this working great.

    However, to get this to work I had to comment out the first line of
    the script which is #!/usr/bin/php -q

    Now the other way the script is called doesn't work any more! This
    other way is that when xxxx@beckhallma lham.com receives an email it
    forwards the email to |/home/beckhall/public_html/php/auto_mail.php5

    Since I removed that first line the forwarder never invokes the
    script! If I put the first line back in then the forwarder works but
    the web post does not. This is because the web post later does a
    HEADER("newurl" ) to do a redirect, and this fails as text has already
    been posted to the form. catch-22!

    Any suggestions? I would guess but I'm no expert that the best
    solution would be to tell the email forwarded to use php to process
    the auto_mail.php5, but I don't know how to do this! Maybe the
    forwarder to go to another script, that then calls auto_mail.php5?

    Cheers for any help,

    Simon
  • C. (http://symcbean.blogspot.com/)

    #2
    Re: using same script in email handling and POST web form

    On Jul 22, 3:35 pm, simon m <SIMON.MA...@us a.netwrote:
    Hi All, I have a script sitting on my web server called
    auto_mail.php5. I would like this to be used two different ways.
    >
    One way would be for a web form to call it as submit action on a form.
    I have got this working great.
    >
    However, to get this to work I had to comment out the first line of
    the script which is #!/usr/bin/php -q
    >
    Now the other way the script is called doesn't work any more! This
    other way is that when x...@beckhallma lham.com receives an email it
    forwards the email to |/home/beckhall/public_html/php/auto_mail.php5
    >
    Since I removed that first line the forwarder never invokes the
    script! If I put the first line back in then the forwarder works but
    the web post does not. This is because the web post later does a
    HEADER("newurl" ) to do a redirect, and this fails as text has already
    been posted to the form. catch-22!
    >
    Any suggestions? I would guess but I'm no expert that the best
    solution would be to tell the email forwarded to use php to process
    the auto_mail.php5, but I don't know how to do this! Maybe the
    forwarder to go to another script, that then calls auto_mail.php5?
    >
    Cheers for any help,
    >
    Simon
    forward the email to |/usr/bin/php -q /home/beckhall/public_html/php/
    auto_mail.php5

    (check the path of PHP - it may not be /usr/bin/php)

    C.

    Comment

    • simon m

      #3
      Re: using same script in email handling and POST web form

      >
      forward the email to |/usr/bin/php -q /home/beckhall/public_html/php/
      auto_mail.php5
      >
      Hi All, I just tried the above but the control panel which I think is
      cpanel X on Apache 1.3.37 (Unix) on a shared server parses out the /
      usr/bin/php -q bit when I paste it into the "forward to" box. There is
      also some help text that says no need to put the php or cgi bits in,
      but be sure to place the appropriate shebang at the top of the script.
      Argh!

      How about a php script that the email forwards to withe shebang, that
      can calls auto_mail.php5? Is there a way to do this, like #include
      another php script in another one?

      Simon

      Comment

      • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

        #4
        Re: using same script in email handling and POST web form

        simon m escribió:
        >forward the email to |/usr/bin/php -q /home/beckhall/public_html/php/
        >auto_mail.ph p5
        >>
        >
        Hi All, I just tried the above but the control panel which I think is
        cpanel X on Apache 1.3.37 (Unix) on a shared server parses out the /
        usr/bin/php -q bit when I paste it into the "forward to" box.
        Then you'll need to write a small shell script to launch it, let's say
        "auto_mail. sh":

        #!/bin/bash
        /usr/bin/php -q /home/beckhall/public_html/php/auto_mail.php5

        And you would forward e-mail to |/path/to/auto_mail.sh



        --
        -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        -- Mi sitio sobre programación web: http://bits.demogracia.com
        -- Mi web de humor al baño María: http://www.demogracia.com
        --

        Comment

        • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

          #5
          Re: using same script in email handling and POST web form

          Álvaro G. Vicario escribió:
          Then you'll need to write a small shell script to launch it, let's say
          "auto_mail. sh":
          >
          #!/bin/bash
          /usr/bin/php -q /home/beckhall/public_html/php/auto_mail.php5
          >
          And you would forward e-mail to |/path/to/auto_mail.sh
          Hmmm... Now I think about it, I'm not sure my sample script is quite
          right... Maybe you need to pass the standard input to the *.php file :-?

          I'm sorry, I should not be writing bash scripts when I don't have any
          Unix box where to test them.


          --
          -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
          -- Mi sitio sobre programación web: http://bits.demogracia.com
          -- Mi web de humor al baño María: http://www.demogracia.com
          --

          Comment

          • simon m

            #6
            Re: using same script in email handling and POST web form

            sorted! I have the original script auto_mail.php5, without the shebang
            and the webpage calls this. All works OK.

            the email now goes to iknow_wrapper.p hp and this has the shebang in
            it, then an include("auto_m ail.php5") in it and that's all.

            yeah! Thanks for all the pointers. I use www.php.net as a mega
            resource, but like a lot of documentation it only really helps when
            you know how to do something and need to clear up the details!

            Simon

            Comment

            Working...