PHP mail not working

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

PHP mail not working

Post 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!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you get any error messages? Do you have any code you could show us?

Mac
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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 =
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

It still doesn't work. How do I check my STMP server?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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."
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Is this your local machine or is it a server?

Mac
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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....
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply