Connecting Tech Pros Worldwide Forums | Help | Site Map

Geting PHP mail to work under linux.

r0g
Guest
 
Posts: n/a
#1: Sep 22 '08
I'd like PHP to send mail to a local mailserver running at localhost:25
like I used to on windows. This mailserver is a dummy server which just
writes the mail to disk for unit testing and works fine when I use
thunderbird to send mail to it and used to work fine under windows
however...

It doesn't work under Ubuntu. Looking at my php.ini file I see...


[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only. You may supply arguments as well (default: "sendmail
-t -i").
;sendmail_path =


Which implies you have to use sendmail. So I downloaded and installed
sendmail and it a) didn't fix this problem and b) made any scripts that
used mail lock up so I have uninstalled it again. Is there any way I can
persuade PHP to simply try to deliver the mail to my local machine's
port 25 (dummy server) like it used to in Windows XP?

Roger.

Michael Fesser
Guest
 
Posts: n/a
#2: Sep 22 '08

re: Geting PHP mail to work under linux.


..oO(r0g)
Quote:
>I'd like PHP to send mail to a local mailserver running at localhost:25
>like I used to on windows. This mailserver is a dummy server which just
>writes the mail to disk for unit testing and works fine when I use
>thunderbird to send mail to it and used to work fine under windows
>however...
>
>It doesn't work under Ubuntu. Looking at my php.ini file I see...
>
>
>[mail function]
>; For Win32 only.
>SMTP = localhost
>smtp_port = 25
>
>; For Win32 only.
>;sendmail_from = me@example.com
>
>; For Unix only. You may supply arguments as well (default: "sendmail
>-t -i").
>;sendmail_path =
>
>
>Which implies you have to use sendmail.
Or any other compatible MTA.
Quote:
>So I downloaded and installed
>sendmail and it a) didn't fix this problem and b) made any scripts that
>used mail lock up so I have uninstalled it again. Is there any way I can
>persuade PHP to simply try to deliver the mail to my local machine's
>port 25 (dummy server) like it used to in Windows XP?
You could use PHPMailer to directly deliver the mail to your server via
SMTP.

Micha
C. (http://symcbean.blogspot.com/)
Guest
 
Posts: n/a
#3: Sep 22 '08

re: Geting PHP mail to work under linux.


On 22 Sep, 06:57, r0g <aioe....@technicalbloke.comwrote:
Quote:
I'd like PHP to send mail to a local mailserver running at localhost:25
like I used to on windows. This mailserver is a dummy server which just
writes the mail to disk for unit testing and works fine when I use
thunderbird to send mail to it and used to work fine under windows
however...
>
It doesn't work under Ubuntu. Looking at my php.ini file I see...
>
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
>
; For Win32 only.
;sendmail_from = m...@example.com
>
; For Unix only. You may supply arguments as well (default: "sendmail
-t -i").
;sendmail_path =
>
Which implies you have to use sendmail. So I downloaded and installed
sendmail and it a) didn't fix this problem and b) made any scripts that
used mail lock up so I have uninstalled it again. Is there any way I can
persuade PHP to simply try to deliver the mail to my local machine's
port 25 (dummy server) like it used to in Windows XP?
>
Roger.
write a replacement for the sendmail binary:

#!/bin/bash

{
date
echo $@
cat
} >>/some/log/file

C.
Norman Peelman
Guest
 
Posts: n/a
#4: Sep 22 '08

re: Geting PHP mail to work under linux.


r0g wrote:
Quote:
I'd like PHP to send mail to a local mailserver running at localhost:25
like I used to on windows. This mailserver is a dummy server which just
writes the mail to disk for unit testing and works fine when I use
thunderbird to send mail to it and used to work fine under windows
however...
>
It doesn't work under Ubuntu. Looking at my php.ini file I see...
>
>
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
>
; For Win32 only.
;sendmail_from = me@example.com
>
; For Unix only. You may supply arguments as well (default: "sendmail
-t -i").
;sendmail_path =
>
>
Which implies you have to use sendmail. So I downloaded and installed
sendmail and it a) didn't fix this problem and b) made any scripts that
used mail lock up so I have uninstalled it again. Is there any way I can
persuade PHP to simply try to deliver the mail to my local machine's
port 25 (dummy server) like it used to in Windows XP?
>
Roger.
I had trouble configuring/using 'sendmail' properly so I ended up
installing 'postfix' ('postfix' calls itself 'sendmail' so you don't
change anything in 'php.ini'). You can find your system mail in
'/var/mail/<usrname>'. You will probably need to edit the
'/etc/postfix/main.cf' file with:

myhostname = <machinehostname>
mydestination = <machinehostname>, localhost.localdomain, localhost
relayhost = <smtp-server.name.here>

You should then be able to send mail local and outbound through PHP's
mail() function. ex: <username>@<machinehostname>

--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
r0g
Guest
 
Posts: n/a
#5: Sep 22 '08

re: Geting PHP mail to work under linux.


Norman Peelman wrote:
Quote:
r0g wrote:
Quote:
>I'd like PHP to send mail to a local mailserver running at localhost:25
>like I used to on windows. This mailserver is a dummy server which just
>writes the mail to disk for unit testing and works fine when I use
>thunderbird to send mail to it and used to work fine under windows
>however...
<snip>
Quote:
Quote:
>Is there any way I can
>persuade PHP to simply try to deliver the mail to my local machine's
>port 25 (dummy server) like it used to in Windows XP?
>>
>Roger.
>
I had trouble configuring/using 'sendmail' properly so I ended up
installing 'postfix' ('postfix' calls itself 'sendmail' so you don't
change anything in 'php.ini'). You can find your system mail in
'/var/mail/<usrname>'. You will probably need to edit the
'/etc/postfix/main.cf' file with:
>
myhostname = <machinehostname>
mydestination = <machinehostname>, localhost.localdomain, localhost
relayhost = <smtp-server.name.here>
>
You should then be able to send mail local and outbound through PHP's
mail() function. ex: <username>@<machinehostname>
>

Hi there and thanks for all you suggestions.

@Michael, PHPmailer would accompish this but I don't want to add any
extra code to my project if I can avoid it so I think I'll hav to go the
MTA route.

@C, I like the simplicity of your suggestion as all these MTA's look
unnecessarily heavy for what I want, but sadly I couldn't get it to
work, plus the unit tests I have expect separate files as generated by
the dummy SMTP server program

@Norman, I'm clearly missing something here - Whenever I install
postfix, no matter what options I choose at install time, it grabs port
25 and my dummy server can't start up. The only time it doesn't is if I
install it and select 'No configuration'. The option that looked best
was 'Internet with smarthost' which let me enter a relay server address
(in my case localhost) and, in main.cf, created exactly the settings you
describe above but it then proceeded to grab port 25 :-{ So my question
is now...

Should I plod on with the 'No configuration' install, plough though
countless forum and Usenet posts and try and make it use my local smtp
server or...

Have I got the wrong end of the stick entirely here?

I'm assuming from the settings in php .ini and what I've read that this
sendmail/postfix mechanism is file/pipe based rather than socket based
and that applications call the application, hand off the mail they want
sending to it, it then contacts the appropriate server (or relay) and
delivers it. If this is the case why is postfix grabbing port 25? And
why can't php on linux just squirt this info straight to a named port
like it can in windows? Am I missing a module or is that just not done?

Yours confused,

Roger Heathcote.


Norman Peelman
Guest
 
Posts: n/a
#6: Sep 22 '08

re: Geting PHP mail to work under linux.


r0g wrote:
Quote:
Norman Peelman wrote:
Quote:
>r0g wrote:
Quote:
>>I'd like PHP to send mail to a local mailserver running at localhost:25
>>like I used to on windows. This mailserver is a dummy server which just
>>writes the mail to disk for unit testing and works fine when I use
>>thunderbird to send mail to it and used to work fine under windows
>>however...
<snip>
>
Quote:
Quote:
>>Is there any way I can
>>persuade PHP to simply try to deliver the mail to my local machine's
>>port 25 (dummy server) like it used to in Windows XP?
>>>
>>Roger.
> I had trouble configuring/using 'sendmail' properly so I ended up
>installing 'postfix' ('postfix' calls itself 'sendmail' so you don't
>change anything in 'php.ini'). You can find your system mail in
>'/var/mail/<usrname>'. You will probably need to edit the
>'/etc/postfix/main.cf' file with:
>>
>myhostname = <machinehostname>
>mydestination = <machinehostname>, localhost.localdomain, localhost
>relayhost = <smtp-server.name.here>
>>
> You should then be able to send mail local and outbound through PHP's
>mail() function. ex: <username>@<machinehostname>
>>
>
>
Hi there and thanks for all you suggestions.
>
@Michael, PHPmailer would accompish this but I don't want to add any
extra code to my project if I can avoid it so I think I'll hav to go the
MTA route.
>
@C, I like the simplicity of your suggestion as all these MTA's look
unnecessarily heavy for what I want, but sadly I couldn't get it to
work, plus the unit tests I have expect separate files as generated by
the dummy SMTP server program
>
@Norman, I'm clearly missing something here - Whenever I install
postfix, no matter what options I choose at install time, it grabs port
25 and my dummy server can't start up. The only time it doesn't is if I
install it and select 'No configuration'. The option that looked best
was 'Internet with smarthost' which let me enter a relay server address
(in my case localhost) and, in main.cf, created exactly the settings you
describe above but it then proceeded to grab port 25 :-{ So my question
is now...
>
Should I plod on with the 'No configuration' install, plough though
countless forum and Usenet posts and try and make it use my local smtp
server or...
>
Have I got the wrong end of the stick entirely here?
>
I'm assuming from the settings in php .ini and what I've read that this
sendmail/postfix mechanism is file/pipe based rather than socket based
and that applications call the application, hand off the mail they want
sending to it, it then contacts the appropriate server (or relay) and
delivers it. If this is the case why is postfix grabbing port 25? And
why can't php on linux just squirt this info straight to a named port
like it can in windows? Am I missing a module or is that just not done?
>
Yours confused,
>
Roger Heathcote.
>
>
I wish I knew more... the only thing I gather is that the relayhost
is for outbound (internet) traffic so maybe it is grabbing port 25 for
that. Try without and you should get local traffic only. My php.ini has
no reference to postfix and in fact is commented out as default install.


--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
r0g
Guest
 
Posts: n/a
#7: Sep 22 '08

re: Geting PHP mail to work under linux.


r0g wrote:
Quote:
Norman Peelman wrote:
Quote:
>r0g wrote:
Quote:
>>I'd like PHP to send mail to a local mailserver running at localhost:25
>>like I used to on windows. This mailserver is a dummy server which just
>>writes the mail to disk for unit testing and works fine when I use
>>thunderbird to send mail to it and used to work fine under windows
>>however...
<snip>
>
Quote:
Quote:
>>Is there any way I can
>>persuade PHP to simply try to deliver the mail to my local machine's
>>port 25 (dummy server) like it used to in Windows XP?
>>>
>>Roger.
> I had trouble configuring/using 'sendmail' properly so I ended up
>installing 'postfix' ('postfix' calls itself 'sendmail' so you don't
>change anything in 'php.ini'). You can find your system mail in
>'/var/mail/<usrname>'. You will probably need to edit the
>'/etc/postfix/main.cf' file with:
>>
>myhostname = <machinehostname>
>mydestination = <machinehostname>, localhost.localdomain, localhost
>relayhost = <smtp-server.name.here>
>>
> You should then be able to send mail local and outbound through PHP's
>mail() function. ex: <username>@<machinehostname>
>>
>
>
Hi there and thanks for all you suggestions.
>
@Michael, PHPmailer would accompish this but I don't want to add any
extra code to my project if I can avoid it so I think I'll hav to go the
MTA route.
>
@C, I like the simplicity of your suggestion as all these MTA's look
unnecessarily heavy for what I want, but sadly I couldn't get it to
work, plus the unit tests I have expect separate files as generated by
the dummy SMTP server program
>
@Norman, I'm clearly missing something here - Whenever I install
postfix, no matter what options I choose at install time, it grabs port
25 and my dummy server can't start up. The only time it doesn't is if I
install it and select 'No configuration'. The option that looked best
was 'Internet with smarthost' which let me enter a relay server address
(in my case localhost) and, in main.cf, created exactly the settings you
describe above but it then proceeded to grab port 25 :-{ So my question
is now...
>
Should I plod on with the 'No configuration' install, plough though
countless forum and Usenet posts and try and make it use my local smtp
server or...
>
Have I got the wrong end of the stick entirely here?
>
I'm assuming from the settings in php .ini and what I've read that this
sendmail/postfix mechanism is file/pipe based rather than socket based
and that applications call the application, hand off the mail they want
sending to it, it then contacts the appropriate server (or relay) and
delivers it. If this is the case why is postfix grabbing port 25? And
why can't php on linux just squirt this info straight to a named port
like it can in windows? Am I missing a module or is that just not done?
>
Yours confused,
>
Roger Heathcote.
>
>
Phew Finally!

After struggling with all the various MTAs I found this wonderful little
SMTP relay program for linux... Nullmailer...
http://untroubled.org/nullmailer/

No fuss, no faff, start the install - it asks you what smtp server(s)
you want to relay your mail to, you tell it, you're done. It just sits
their pretending to be sendmail and forwarding all mail from PHP to port
25 just like I wanted :-)

Roger Heathcote.
http://untroubled.org/nullmailer/
Norman Peelman
Guest
 
Posts: n/a
#8: Sep 22 '08

re: Geting PHP mail to work under linux.


r0g wrote:
Quote:
r0g wrote:
Quote:
>Norman Peelman wrote:
Quote:
>>r0g wrote:
>>>I'd like PHP to send mail to a local mailserver running at localhost:25
>>>like I used to on windows. This mailserver is a dummy server which just
>>>writes the mail to disk for unit testing and works fine when I use
>>>thunderbird to send mail to it and used to work fine under windows
>>>however...
><snip>
>>
Quote:
>>>Is there any way I can
>>>persuade PHP to simply try to deliver the mail to my local machine's
>>>port 25 (dummy server) like it used to in Windows XP?
>>>>
>>>Roger.
>> I had trouble configuring/using 'sendmail' properly so I ended up
>>installing 'postfix' ('postfix' calls itself 'sendmail' so you don't
>>change anything in 'php.ini'). You can find your system mail in
>>'/var/mail/<usrname>'. You will probably need to edit the
>>'/etc/postfix/main.cf' file with:
>>>
>>myhostname = <machinehostname>
>>mydestination = <machinehostname>, localhost.localdomain, localhost
>>relayhost = <smtp-server.name.here>
>>>
>> You should then be able to send mail local and outbound through PHP's
>>mail() function. ex: <username>@<machinehostname>
>>>
>>
>Hi there and thanks for all you suggestions.
>>
>@Michael, PHPmailer would accompish this but I don't want to add any
>extra code to my project if I can avoid it so I think I'll hav to go the
>MTA route.
>>
>@C, I like the simplicity of your suggestion as all these MTA's look
>unnecessarily heavy for what I want, but sadly I couldn't get it to
>work, plus the unit tests I have expect separate files as generated by
>the dummy SMTP server program
>>
>@Norman, I'm clearly missing something here - Whenever I install
>postfix, no matter what options I choose at install time, it grabs port
>25 and my dummy server can't start up. The only time it doesn't is if I
>install it and select 'No configuration'. The option that looked best
>was 'Internet with smarthost' which let me enter a relay server address
>(in my case localhost) and, in main.cf, created exactly the settings you
>describe above but it then proceeded to grab port 25 :-{ So my question
>is now...
>>
>Should I plod on with the 'No configuration' install, plough though
>countless forum and Usenet posts and try and make it use my local smtp
>server or...
>>
>Have I got the wrong end of the stick entirely here?
>>
>I'm assuming from the settings in php .ini and what I've read that this
>sendmail/postfix mechanism is file/pipe based rather than socket based
>and that applications call the application, hand off the mail they want
>sending to it, it then contacts the appropriate server (or relay) and
>delivers it. If this is the case why is postfix grabbing port 25? And
>why can't php on linux just squirt this info straight to a named port
>like it can in windows? Am I missing a module or is that just not done?
>>
>Yours confused,
>>
>Roger Heathcote.
>>
>>
>
Phew Finally!
>
After struggling with all the various MTAs I found this wonderful little
SMTP relay program for linux... Nullmailer...
http://untroubled.org/nullmailer/
>
No fuss, no faff, start the install - it asks you what smtp server(s)
you want to relay your mail to, you tell it, you're done. It just sits
their pretending to be sendmail and forwarding all mail from PHP to port
25 just like I wanted :-)
>
Roger Heathcote.
http://untroubled.org/nullmailer/
Glad you got something working.

--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
Closed Thread