View Full Version : Mail in PHP
jac2703
09-18-06, 10:48 PM
Hi all. I have a small dev server set up on linux Fedora Core 5. I am running apache 2x and php 5x. I use Merak mail server for pop3/smtp.
I have written a test php script to send mail => mail() but this is not being recieved. Can anyone point me in the right direction?
Thanks for your time
James
UnrealEd
09-19-06, 03:00 AM
what error did you get, or didn't you get anyone?
are you sure it's not delivered, it could just be located in your trash/spam folder?
could you post some settings from your mail program, such as: host, port, ...
could you also post your php.ini settings about your smtp?
Greetz,
UnrealEd
jac2703
09-20-06, 04:06 AM
Hi UrealEd
Thanks for takin your time to help.
PHP settings regarding sendmail are as follows:
[mail function]
;for windows
SMTP = localhost
smpt_port = 25
; For unix only...
sendmail_path = /usr/sbin/sendmail -t -i
Mail settings:
Host: jamescoyle.net
Port: 25
Mail does send fine from the server through smtp (eg using thunderbird).
Spam settings on the mail server are turned off and no mail is recieved in thunderbird, inbox or trash.
James
Since you are using an SMTP server, you are not using the Unix sendmail program and the following line should remain commented out -
sendmail_path = /usr/sbin/sendmail -t -iIf you have not done so, put the following line at the start of your PHP code to get the maximum information and/or check the web server logs -
error_reporting(E_ALL);
jac2703
09-20-06, 04:30 AM
Hi mab. I currently have error_reporting = E_ALL in php.ini.
There does not appear to be an error, just no mail is sent. I have an smtp server but was wanting to send php mail through sendmail.
regards
James
PS. php mail through smtp would not be a problem, as long as the mail is sent!
Thanks again for your time.
By having settings for both SMTP and sendmail in the php.ini, I don't know what php will do, but I believe (don't quote me on this) that it will attempt to use SMTP and talk with the server listening on port 25.
If sendmail is installed, it is listening on port 25 so I believe that both your Merak server and the sendmail server are in conflict.
There are a number of reasons why PHP might not be able to send email through an SMTP server, such as authentication is being used or relaying is not allowed and either the From or To address does not match an account hosted on the mail server.
The best way around this is to use a php class which contains its own smtp implementation. I use this one:
http://phpmailer.sourceforge.net/
Maybe it helps!
jac2703
09-20-06, 04:21 PM
Hi,
It looks like mab is correct and there is a conflict as two services are trying to use port 25. Can i forget sendmail and use the smtp mail server to deliver php mail?
The PHP.ini file states:
[mail function]
;for windows
SMTP = localhost
smpt_port = 25
Which is correct however is seems to suggest that these settings are only for windows and not linux. Can we not use smtp servers for php in linux?
I am sure that the PHP mail(...) function can use any available SMTP server (at least those not requiring authentication) by using the SMTP = and smpt_port = settings. It is my impression that PHP won't use sendmail if the php.ini config line is commented out - sendmail_path = /usr/sbin/sendmail -t -i. However, you still need to disable sendmail so that it is not listening on port 25 for incoming mail.
I am not familiar with linux so I cannot specifically advise on how to disable the sendmail service. If you cannot determine how to disable it, but you can find the config file that sets the port number, you could change it to port 26... so that there is no longer a conflict.
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.