Page 1 of 1

Cant send a simple email... Mail() function always fails

Posted: Thu Apr 12, 2007 3:03 pm
by Ender22
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey...
This seems to be something incredibly easy, but I have tried the sample scripts from many sites and I cant get any of them to send an email from my php page. 

Heres the code im using.

Code: Select all

<?php
				$to = 'oneOfMyEmails@gmail.com';
				$subject = 'the subject';
				$from = 'anotherOneOfMyEmails@hotmail.com';
				$message = 'hello';

				if(mail($to, $subject, $message, "From: $from"))
  					echo "Mail sent"; // this never gets called
				else
 					echo "Mail send failure - message not sent"; // this error always happens
?>
Is there some setting in php.ini file or something I need to change?
Also im sure the emails are not being sent to my junk folder or anything else, I have checked... but the else (Mail send failure) statement is always executed so the emails are not sending at all.


this should be easy... right??? :(

any help is greatly appreciated! :D


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Apr 12, 2007 3:04 pm
by Chris Corbyn
Windows or linux server? You either need to set sendmail_path or SMTP depending upon your OS.

Posted: Thu Apr 12, 2007 4:46 pm
by Ender22
Its windows. Im using IIS server.
Do I set these in my php.ini file?

I found this in the ini file...

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

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

do i need to change what SMTP is equal to?

Can you please give me a few more details?

Posted: Thu Apr 12, 2007 4:58 pm
by guitarlvr
SMTP should equal smtp.domain.com. Whatever the address is to you smtp server. (can also be an ip address). The port should be 25 unless otherwise specified by your email administrator and the sendmail_from can really be anything you feel like putting in there. Also make sure you set your date.timezone setting in php.ini. I have gotten errors from not having that also. Hope that helps.

Wayne

Posted: Thu Apr 12, 2007 7:29 pm
by Ender22
Sorry... I have no idea what smtp is, or even if i have a smtp server? So i have no idea what to change it to.
Also I dont think I have a email administator (im just hosting everything on my local machine using iis at the moment) and i was just planning to use a gmail account as the account the emails are sent from.

so, whats smtp and how can I find out what the address to my smtp server is?

thanks!