test mail() on development machine w/o smtp server

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

    test mail() on development machine w/o smtp server

    My development machine (WinXP, Apache 2.2.4) does not have an smtp
    server, and I don't really want to install one if I can help it.

    Does anyone know of a simple method of testing php scripts that employ
    mail() by simulating an smtp server and directing output to a text file
    or to an installed text editor.

    Right now I can modify the script to use something instead of mail(),
    then change it when I put into production, but I would really like to
    test the script in its production form w/o having to actually send email.


    Bill
  • Rik

    #2
    Re: test mail() on development machine w/o smtp server

    On Sun, 17 Jun 2007 17:05:43 +0200, William Gill <noreply@gcgrou p.net>
    wrote:
    My development machine (WinXP, Apache 2.2.4) does not have an smtp
    server, and I don't really want to install one if I can help it.
    Don't need to, just use any SMTP server you like, it's not like working
    with sockets on UNIX. Local, ISP, doesn't matter.
    Does anyone know of a simple method of testing php scripts that employ
    mail() by simulating an smtp server and directing output to a text file
    or to an installed text editor.
    >
    Right now I can modify the script to use something instead of mail(),
    then change it when I put into production, but I would really like to
    test the script in its production form w/o having to actually send email.
    >
    Why go to the trouble of simulating an SMTP server? Define a function
    my_mail(), let it log to a file while testing, let it call mail() on
    production, and you're set. Just one little change ( or pehaps even make
    the function behaviour dependend on some enivronmental variables so it
    automatically chooses the right action.
    --
    Rik Wasmus

    Comment

    • William Gill

      #3
      Re: test mail() on development machine w/o smtp server

      That works, but then I need to go pull the email (assuming I was on the
      original distribution) and verify everything was as expected. If I
      could simulate the smtp server I could check the format and content
      regardless of who it's actually sent to.

      Bill

      Rik wrote:
      On Sun, 17 Jun 2007 17:05:43 +0200, William Gill <noreply@gcgrou p.net>
      wrote:
      >
      >My development machine (WinXP, Apache 2.2.4) does not have an smtp
      >server, and I don't really want to install one if I can help it.
      >
      Don't need to, just use any SMTP server you like, it's not like working
      with sockets on UNIX. Local, ISP, doesn't matter.
      >
      >Does anyone know of a simple method of testing php scripts that employ
      >mail() by simulating an smtp server and directing output to a text
      >file or to an installed text editor.
      >>
      >Right now I can modify the script to use something instead of mail(),
      >then change it when I put into production, but I would really like to
      >test the script in its production form w/o having to actually send email.
      >>
      >
      Why go to the trouble of simulating an SMTP server? Define a function
      my_mail(), let it log to a file while testing, let it call mail() on
      production, and you're set. Just one little change ( or pehaps even make
      the function behaviour dependend on some enivronmental variables so it
      automatically chooses the right action.
      --Rik Wasmus

      Comment

      • Rik

        #4
        Re: test mail() on development machine w/o smtp server

        On Sun, 17 Jun 2007 18:58:34 +0200, William Gill <noreply@gcgrou p.net>
        wrote:
        That works, but then I need to go pull the email (assuming I was on the
        original distribution) and verify everything was as expected. If I
        could simulate the smtp server I could check the format and content
        regardless of who it's actually sent to.
        >
        Or you could 'override' the 'to' (CC/BCC) fields in you
        my_mail()-function, so it'll always be sent to you, possibly with the
        original emailadresses in another header/in the content.


        --
        Rik Wasmus

        Comment

        • gosha bine

          #5
          Re: test mail() on development machine w/o smtp server

          William Gill wrote:
          My development machine (WinXP, Apache 2.2.4) does not have an smtp
          server, and I don't really want to install one if I can help it.
          >
          Does anyone know of a simple method of testing php scripts that employ
          mail() by simulating an smtp server and directing output to a text file
          or to an installed text editor.

          I have the following in my php.ini

          sendmail_path = php -r
          "file_put_conte nts('c:/mail.log',file_ get_contents('p hp://stdin'),FILE_AP PEND);"

          this logs all emails sent via mail() to c:\mail.log


          --
          gosha bine

          extended php parser ~ http://code.google.com/p/pihipi
          blok ~ http://www.tagarga.com/blok

          Comment

          • William Gill

            #6
            Re: test mail() on development machine w/o smtp server

            That's a thought! It still means going to mail to see the result, but
            using IMAP I could leave that window open while I test.

            I just have to remember to always use the my_mail() wrapper instead of
            mail().

            Thanks,

            Bill


            Rik wrote:
            On Sun, 17 Jun 2007 18:58:34 +0200, William Gill <noreply@gcgrou p.net>
            wrote:
            >
            >That works, but then I need to go pull the email (assuming I was on
            >the original distribution) and verify everything was as expected. If
            >I could simulate the smtp server I could check te format and content
            >regardless of who it's actually sent to.
            >>
            >
            Or you could 'override' the 'to' (CC/BCC) fields in you
            my_mail()-function, so it'll always be sent to you, possibly with the
            original emailadresses in another header/in the content.
            >
            >
            --Rik Wasmus

            Comment

            • Michael Fesser

              #7
              Re: test mail() on development machine w/o smtp server

              ..oO(gosha bine)
              >William Gill wrote:
              >>
              >Does anyone know of a simple method of testing php scripts that employ
              >mail() by simulating an smtp server and directing output to a text file
              >or to an installed text editor.
              >
              >I have the following in my php.ini
              >
              >sendmail_pat h = php -r
              >"file_put_cont ents('c:/mail.log',file_ get_contents('p hp://stdin'),FILE_AP PEND);"
              >
              >this logs all emails sent via mail() to c:\mail.log
              Nice idea ...

              Micha

              Comment

              • William Gill

                #8
                Re: test mail() on development machine w/o smtp server

                Looks good, but it causes a parsing error on WinXP. I may use it on my
                Linux boxes though.

                Bill

                gosha bine wrote:
                William Gill wrote:
                >My development machine (WinXP, Apache 2.2.4) does not have an smtp
                >server, and I don't really want to install one if I can help it.
                >>
                >Does anyone know of a simple method of testing php scripts that employ
                >mail() by simulating an smtp server and directing output to a text
                >file or to an installed text editor.
                >
                >
                I have the following in my php.ini
                >
                sendmail_path = php -r
                "file_put_conte nts('c:/mail.log',file_ get_contents('p hp://stdin'),FILE_AP PEND);"
                >
                >
                this logs all emails sent via mail() to c:\mail.log
                >
                >

                Comment

                • gosha bine

                  #9
                  Re: test mail() on development machine w/o smtp server

                  William Gill wrote:
                  Looks good, but it causes a parsing error on WinXP. I may use it on my
                  Linux boxes though.
                  Works just fine for me. Make sure you've copied it properly.
                  Also, please do not top-post. Post your replies below the quoted text.

                  >
                  Bill
                  >
                  gosha bine wrote:
                  >William Gill wrote:
                  >>My development machine (WinXP, Apache 2.2.4) does not have an smtp
                  >>server, and I don't really want to install one if I can help it.
                  >>>
                  >>Does anyone know of a simple method of testing php scripts that
                  >>employ mail() by simulating an smtp server and directing output to a
                  >>text file or to an installed text editor.
                  >>
                  >>
                  >I have the following in my php.ini
                  >>
                  >sendmail_pat h = php -r
                  >"file_put_cont ents('c:/mail.log',file_ get_contents('p hp://stdin'),FILE_AP PEND);"
                  >>
                  >>
                  >this logs all emails sent via mail() to c:\mail.log
                  >>
                  >>

                  --
                  gosha bine

                  extended php parser ~ http://code.google.com/p/pihipi
                  blok ~ http://www.tagarga.com/blok

                  Comment

                  • William Gill

                    #10
                    Re: test mail() on development machine w/o smtp server


                    gosha bine wrote:
                    William Gill wrote:
                    >Looks good, but it causes a parsing error on WinXP. I may use it on
                    >my Linux boxes though.
                    >
                    Works just fine for me. Make sure you've copied it properly.
                    Fixing the cut and paste error, and commenting out the "SMTP =" and
                    'smtp_port =' entries fixed the parse error. Now Xp is complaining
                    about php not being a recognized command when it's called from inside
                    Apache.

                    I'll keep fiddling with it.
                    Also, please do not top-post. Post your replies below the quoted text.
                    Mea culpa.
                    >
                    >
                    >>
                    >Bill
                    >>
                    >gosha bine wrote:
                    >>William Gill wrote:
                    >>>My development machine (WinXP, Apache 2.2.4) does not have an smtp
                    >>>server, and I don't really want to install one if I can help it.
                    >>>>
                    >>>Does anyone know of a simple method of testing php scripts that
                    >>>employ mail() by simulating an smtp server and directing output to a
                    >>>text file or to an installed text editor.
                    >>>
                    >>>
                    >>I have the following in my php.ini
                    >>>
                    >>sendmail_pa th = php -r
                    >>"file_put_con tents('c:/mail.log',file_ get_contents('p hp://stdin'),FILE_AP PEND);"
                    >>>
                    >>>
                    >>this logs all emails sent via mail() to c:\mail.log
                    >>>
                    >>>
                    >
                    >

                    Comment

                    • shimmyshack

                      #11
                      Re: test mail() on development machine w/o smtp server

                      On Jun 17, 10:22 pm, gosha bine <stereof...@gma il.comwrote:
                      William Gill wrote:
                      My development machine (WinXP, Apache 2.2.4) does not have an smtp
                      server, and I don't really want to install one if I can help it.
                      >
                      Does anyone know of a simple method of testing php scripts that employ
                      mail() by simulating an smtp server and directing output to a text file
                      or to an installed text editor.
                      >
                      I have the following in my php.ini
                      >
                      sendmail_path = php -r
                      "file_put_conte nts('c:/mail.log',file_ get_contents('p hp://stdin'),FILE_AP PEND);"
                      >
                      this logs all emails sent via mail() to c:\mail.log
                      >
                      --
                      gosha bine
                      >
                      extended php parser ~http://code.google.com/p/pihipi
                      blok ~http://www.tagarga.com/blok
                      thanks for that idea, very nice. (verified on xp)

                      Comment

                      • William Gill

                        #12
                        Re: test mail() on development machine w/o smtp server



                        gosha bine wrote:
                        William Gill wrote:
                        >Looks good, but it causes a parsing error on WinXP. I may use it on
                        >my Linux boxes though.
                        >
                        Works just fine for me. Make sure you've copied it properly.
                        Finally! I had to put the entire path specification to php.exe, even
                        though it was clearly in %PATH%. Anyway works great and is just what I
                        needed.
                        Also, please do not top-post. Post your replies below the quoted text.
                        >
                        >
                        >>
                        >Bill
                        >>
                        >gosha bine wrote:
                        >>William Gill wrote:
                        >>>My development machine (WinXP, Apache 2.2.4) does not have an smtp
                        >>>server, and I don't really want to install one if I can help it.
                        >>>>
                        >>>Does anyone know of a simple method of testing php scripts that
                        >>>employ mail() by simulating an smtp server and directing output to a
                        >>>text file or to an installed text editor.
                        >>>
                        >>>
                        >>I have the following in my php.ini
                        >>>
                        >>sendmail_pa th = php -r
                        >>"file_put_con tents('c:/mail.log',file_ get_contents('p hp://stdin'),FILE_AP PEND);"
                        >>>
                        >>>
                        >>this logs all emails sent via mail() to c:\mail.log
                        >>>
                        >>>
                        >
                        >
                        Thanks,

                        Bill

                        Comment

                        • gosha bine

                          #13
                          Re: test mail() on development machine w/o smtp server

                          On 18.06.2007 01:51 William Gill wrote:
                          >
                          gosha bine wrote:
                          >William Gill wrote:
                          >>Looks good, but it causes a parsing error on WinXP. I may use it on
                          >>my Linux boxes though.
                          >>
                          >Works just fine for me. Make sure you've copied it properly.
                          >
                          Fixing the cut and paste error, and commenting out the "SMTP =" and
                          'smtp_port =' entries fixed the parse error. Now Xp is complaining
                          about php not being a recognized command when it's called from inside
                          Apache.
                          Add php directory to your path (My
                          Computer/Properties/Advanced/Environment, edit PATH then restart Apache)
                          or provide the full path to php executable (e.g. c:\path\to\php\ php.exe)

                          --
                          gosha bine

                          extended php parser ~ http://code.google.com/p/pihipi
                          blok ~ http://www.tagarga.com/blok

                          Comment

                          • gosha bine

                            #14
                            Re: test mail() on development machine w/o smtp server

                            William Gill wrote:
                            >
                            >
                            gosha bine wrote:
                            >William Gill wrote:
                            >>Looks good, but it causes a parsing error on WinXP. I may use it on
                            >>my Linux boxes though.
                            >>
                            >Works just fine for me. Make sure you've copied it properly.
                            >
                            Finally! I had to put the entire path specification to php.exe, even
                            though it was clearly in %PATH%. Anyway works great and is just what I
                            needed.
                            >
                            Glad to hear it was helpful, Bill.

                            --
                            gosha bine

                            extended php parser ~ http://code.google.com/p/pihipi
                            blok ~ http://www.tagarga.com/blok

                            Comment

                            • Patrick

                              #15
                              Re: test mail() on development machine w/o smtp server

                              On Jun 17, 5:22 pm, gosha bine <stereof...@gma il.comwrote:
                              William Gill wrote:
                              My development machine (WinXP, Apache 2.2.4) does not have an smtp
                              server, and I don't really want to install one if I can help it.
                              >
                              Does anyone know of a simple method of testing php scripts that employ
                              mail() by simulating an smtp server and directing output to a text file
                              or to an installed text editor.
                              >
                              I have the following in my php.ini
                              >
                              sendmail_path = php -r
                              "file_put_conte nts('c:/mail.log',file_ get_contents('p hp://stdin'),FILE_AP PEND);"
                              >
                              this logs all emails sent via mail() to c:\mail.log
                              >
                              --
                              gosha bine
                              >
                              extended php parser ~http://code.google.com/p/pihipi
                              blok ~http://www.tagarga.com/blok
                              I would like to try this with my linux box. Do I put that line below
                              my sendmail_path line? 'php://...' has to be replaced with what for
                              linux?

                              Anything else I need to change? for example, I'm not sure if I should
                              put my global smtp server(google) where it says SMTP = localhost and
                              remove localhost, because it says just above it 'For Win32 only'.

                              I think I'm getting confused over reply.. basically, what is the step
                              by step procedure for this alternative you mention(other smtp, instead
                              of setting one up) in a Linux box?

                              Thanks,
                              -Patrick

                              Comment

                              Working...