Page 1 of 2

PHP mail not working

Posted: Thu Nov 17, 2005 11:26 am
by ljCharlie
I'm using IIS server for my website. I'm not sure where to check for the setting but a form sends email, the email doesn't get to the destination. Your help is needed.

Thanks!

Posted: Thu Nov 17, 2005 11:28 am
by twigletmac
Do you get any error messages? Do you have any code you could show us?

Mac

Posted: Thu Nov 17, 2005 11:42 am
by Burrito
on windows server, PHP uses SMTP to send mail. You need to make sure that you specified the address of the smtp server in your php.ini file and that the server will allow mail to be sent from your php server.

Posted: Thu Nov 17, 2005 12:14 pm
by ljCharlie
This is what I have in my php.ini
[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 =

Posted: Thu Nov 17, 2005 12:20 pm
by Burrito
you need to uncomment the "sendmail_from" line if you're not including the "from" header when sending mail (by default the mail() function does not).

try that first and see if you have success, I'm guessing you won't so if you don't, you need to check the settings on your smtp server (localhost apparently) and make sure that it will allow mail to be sent from php.

Posted: Thu Nov 17, 2005 12:30 pm
by ljCharlie
It still doesn't work. How do I check my STMP server?

Posted: Thu Nov 17, 2005 12:33 pm
by Burrito
first off, can you even send mail through your smtp server via some other means (ie a mail client)?

what are you using for your mail server? How to check settings on that depends entirely on what you're using.

Posted: Thu Nov 17, 2005 12:36 pm
by ljCharlie
Here's the code I use to send email.

Code: Select all

ini_set("sendmail_from",$Email);	
		$headers = "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
		$headers .= "From: '".$Email."'\r\n";						
		if (mail($toEmailAddress, $Subject, $message, $headers)){
			echo "Your message has been successfully sent.<br>";
			}
		else{ echo "An error occurred while sending your message.";}
The error I got is "An error occurred while sending your message."

Posted: Thu Nov 17, 2005 12:38 pm
by Burrito
here we go again with the super-dee-duper long thread discussion...heh

can you send mail via another means through your smtp server? Do you even have an smtp server set up on the same machine that php is installed?

Posted: Thu Nov 17, 2005 12:39 pm
by twigletmac
Is this your local machine or is it a server?

Mac

Posted: Thu Nov 17, 2005 12:41 pm
by Burrito
per his php.ini he's trying to send it from the same machine that php is installed.
[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 =
/me is starting to think he doesn't have a mail server set up there....

Posted: Thu Nov 17, 2005 12:45 pm
by ljCharlie
Okay, perhaps I should ask this?

In the Control Panel/Add&Remove/Component Wizard, should I enable E-Mail Services or Application Server/IIS/SMTP? Which service I should be turning on for this php smtp email to work?

Posted: Thu Nov 17, 2005 12:45 pm
by twigletmac
Burrito wrote:/me is starting to think he doesn't have a mail server set up there....
But if it's a local machine it won't need one - he can probably just use his ISP's SMTP.

Mac

Posted: Thu Nov 17, 2005 12:47 pm
by Burrito
twigletmac wrote:
Burrito wrote:/me is starting to think he doesn't have a mail server set up there....
But if it's a local machine it won't need one - he can probably just use his ISP's SMTP.
in which case shouldn't he point the smtp in php.ini to his ISP's smtp server?

Posted: Thu Nov 17, 2005 12:55 pm
by twigletmac
Burrito wrote:
twigletmac wrote:
Burrito wrote:/me is starting to think he doesn't have a mail server set up there....
But if it's a local machine it won't need one - he can probably just use his ISP's SMTP.
in which case shouldn't he point the smtp in php.ini to his ISP's smtp server?
exatomundo

Mac