470,819 Members | 1,568 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,819 developers. It's quick & easy.

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
Jun 17 '07 #1
17 3654
Rik
On Sun, 17 Jun 2007 17:05:43 +0200, William Gill <no*****@gcgroup.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
Jun 17 '07 #2
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 <no*****@gcgroup.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
Jun 17 '07 #3
Rik
On Sun, 17 Jun 2007 18:58:34 +0200, William Gill <no*****@gcgroup.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
Jun 17 '07 #4
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_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"

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
Jun 17 '07 #5
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 <no*****@gcgroup.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
Jun 17 '07 #6
..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_path = php -r
"file_put_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"

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

Micha
Jun 17 '07 #7
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_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"
this logs all emails sent via mail() to c:\mail.log

Jun 17 '07 #8
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_path = php -r
"file_put_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"
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
Jun 17 '07 #9

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_path = php -r
"file_put_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"
this logs all emails sent via mail() to c:\mail.log


Jun 18 '07 #10
On Jun 17, 10:22 pm, gosha bine <stereof...@gmail.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_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"

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)

Jun 18 '07 #11


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_path = php -r
"file_put_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"
this logs all emails sent via mail() to c:\mail.log


Thanks,

Bill
Jun 18 '07 #12
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
Jun 18 '07 #13
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
Jun 18 '07 #14
On Jun 17, 5:22 pm, gosha bine <stereof...@gmail.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_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"

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

Jun 19 '07 #15
On Jun 19, 1:56 am, Patrick <CaptainMorganRa...@gmail.comwrote:
On Jun 17, 5:22 pm, gosha bine <stereof...@gmail.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_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"
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
you can either configure your sendmail to connect to google (probably
via stunnel or putty) and pass the email on that way, or you could
write a small script that took the php://stdin and uses phpmailer to
connect to google for you (again probably through something that can
handle SSL) you get the added bonus of having being able to dump the
mail locally before it is sent by phpmailer.
both of these options use the method above with a tweak to either your
sendmail executable, or the script that handles the mail.

Jun 19 '07 #16
OK forgive my ignorance, but this has been bugging me since you posted
the solution. Could you explain the notation "php://stdin". I thought
stdin was stdin, is there a way to differentiate?

Again, forgive my ignorance.

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_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"
this logs all emails sent via mail() to c:\mail.log

Jun 23 '07 #17

William Gill wrote:
OK forgive my ignorance, but this has been bugging me since you posted
the solution. Could you explain the notation "php://stdin". I thought
stdin was stdin, is there a way to differentiate?

Again, forgive my ignorance.

Bill
Never mind, I finally found the manual reference for input/output streams.

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_contents('c:/mail.log',file_get_contents('php://stdin'),FILE_APPEND);"
this logs all emails sent via mail() to c:\mail.log

Thanks,

bill
Jun 23 '07 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Karuna | last post: by
2 posts views Thread by \Crash\ Dummy | last post: by
4 posts views Thread by Gerhard | last post: by
5 posts views Thread by Pascal Cloup | last post: by
1 post views Thread by Tiabes | last post: by
3 posts views Thread by Ing. Davide Piras | last post: by
4 posts views Thread by =?Utf-8?B?UmljaA==?= | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.