473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 3763
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Karuna | last post by:
Hi everybody, I have been trying to write a simple mail script using PHP and apache on Windows XP. Eventhough the script is saying that the mail is successfully sent, I am unable get it in my...
2
by: \Crash\ Dummy | last post by:
I would like to use a form on my web site to e-mail user comments to me. I have ASP capability to run server side scripts. The host domain has a SMTP server, but I don't know if it is on the same...
4
by: Gerhard | last post by:
Hi, I some asp.net beta 2 code that works fine on an XP Pro machine, but on a Windows 2003 Server gets the following error: System.Net.Mail.SmtpFailedRecipientException {"Mailbox unavailable....
1
by: Robert V. Hanson | last post by:
Please give me some ideas on how to setup the ability to test System.Web.Mail code to send emails using just my development computer, Win2000Pro OS and IIS5.0? Thanks, Bob Hanson
5
by: Pascal Cloup | last post by:
Hello, I just want to send an e-mail from my windows form application without specifying SmtpServer. On my computer, when i specify my smtpserver, SmtpMail.Send( aMail ) works fine, but...
1
by: Tiabes | last post by:
Hi, I am using System.Web.Mail for a email feature in an Intranet Application (ASP.NET). I need to use NTLM Authentication: ...
3
by: Ing. Davide Piras | last post by:
Hi there, I use Visual Studio 2005, c# projects... I like the new unit test framework very much, it helps a lot mantaining and growing up a project with the test driven paradigm, that's so good!...
9
by: Homer | last post by:
Hi, I've posted this question before but didn't get anywhere with it. Please help me out if you know of a solution for it. I got "InnerException: Unable to connect to remote server"..."No...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
I want to build an simple email smtp client app similar to outlook except with some custom features for a personal computer that uses comcast cable. The owner of the computer said she doesn't have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.