Quick question...For the email code in the PHP script to work, do I have to make any server settings? or make any accomodation for the type of server it is being run on? If so, then please guide me...

The application is located on a Linux server.

Hi maydhyam,
if you use a professional hosting (someone has set up the server for you) you don't have to worry about anything. Just use mail().

If you're running your own server (e.g. development server) then you need to check php.ini section [mail function]. For Linux you have to verify that sendmail_path is correct.

Ok, I'm not quite sure what to do...I found the php.ini file, and this is what it says:

[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 =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

That's it. You said you have a linux box so you have to locate sendmail - I assume that you have it installed. To find where your sendmail is run:

locate sendmail

then uncomment the sendmail_path row and enter the full path incl. the switches. For example:

sendmail_path = /usr/sbin/sendmail -t -i

That should do.

Just curious: are you able to send e-mails from the box using pine or mutt? PHP usually works with default settings just fine if sendmail isn't installed into some unusual location. What I mean is that you could in fact, be having a sendmail problem, not PHP configuration problem.

Nevermind what I said do what Petr.Pavel says :D


Thank You Petr 'PePa' Pavel, it worked like a charm...
Thanks All..


I have a php form that will not send the email to the selected email address. I spoke to the host about switching the php.ini settings but it still is not working correctly. It is hosted on a linux platform. I need some help to get this working.

My code is correct. When I tested the form on my local server it sends to the correct address, but when its uploaded to the server the mail does not send. Any help would be appreciated

Hi there,
since you don't have a control over the server there's nothing you can do to in order to make the default mail() function work.

To be really really sure create a file with just one line:

mail('your@address.com', 'this is a test', 'test body');

I have been sure so many times and yet I was proven wrong later. So it's best to make your tests as simple as possible.

If you get the test message when run on your dev box but not from the production server you should give this script to the hosting company and tell them to fix their setup.

If they tell you to screw yourself you'll have to work around it. Consider using some mail() replacement like the excellent XPertMailer:
You can switch it to use a direct SMTP connection instead of default mail() function. For that case you will need to know what's your hosting's SMTP server for outgoing connections. Or you will have to use some other SMTP server, likely with SMTP authentication turned on.

XPertMailer has one additional feature and that is to connect to SMTP server of the recipient domain. That way the e-mail is sent through different SMTP servers, no need to use your own SMTP server.