Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Mail not working 1

Status
Not open for further replies.

MostC

IS-IT--Management
Nov 26, 2007
9
US
Hello,

I have the following configuration:

Windows Server 2003
IIS 6
PHP 5
MySQL (current version just installed)
Postcast Free Server 2.6


Everything seems to work fine. I can assign variables, access the database, etc. However I can not seem to send any email of any type. I modified the PHP.ini file to include:

extension=php_smtp.dll (not sure what this is for, but it's there)
SMTP = localhost
smtp_port = 25

I have tested sending an email with the postcast server and it works fine.

Here is the code:

mail("myemail@mydomain.com", "Subject Hello", "hello", "info@mydomain.com");

I am trying something simple first to verify it is working then I will try and get it to work with some html. I looked through phpinfo and saw the SMTP = localhost and the smtp_port = 25. I did not see any heading for SMTP but I am not sure if I am supposed to. Any ideas? Are there any log files I can look at that may hint at something? I get nothing back as a reply so I can't tell if something failed or not.

Thanks,

MostC
 
have you got an smtp server running locally? will it accept relay requests from unauthenticated users?

the last parameter you have used is for headers. This means it should look a fully formed header

Code:
$headers = "From: info@domain.com\r\n";
if (mail("myemail@mydomain.com", "Subject Hello", "hello", $headers)){
 //mail sent to the server ok
} else {
 echo "problem sending mail";
}
 
Thanks jpadie,

I have actually tried this two different ways. The first one was with my Exchange server in which I opened up the web servers ip for relaying then tested with telnet. I then decided to try the postcast smtp server which is a free download and is designed to do relaying. Neither worked.
You are correct and I need to remove the $headers. I forgot to remove this when I copied it over from a spot I remarked out.
Reading a PHP book last night it looks like there are some error reporting parameters I can open up in the php.ini. I think I will look into this today and see if I get anything reported back.

MostC
 
there are some error handlers in php but this won't help you too much with the mail command.

if my code does not throw an error then php is delivering the mail adequately to the smtp service. so the next stage is to look at the smtp mail logs.
 
Well I just tried the code you posted and it comes back with "problem sending mail". Do you have any ideas why it would come up false?

MostC
 
turn error handling on just in case you get a decent message back

at the beginning of the script
Code:
error_reporting (E_ALL);
ini_set('display_errors', 'on');
 
Hey jpadie,
Thanks for the info. I got it to send the mail through the Exchange server. It was failing on the postcast system. I am going to leave the error handling on for a little while and see why the rest of the code is not sending but my main problem has been solved.
I set the error handling in the php.ini but it is good to know about putting this in the code. I will do that aslo.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top