Link to home
Start Free TrialLog in
Avatar of Chris Kenward
Chris KenwardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PHP Email not working Windows 2008 R2

I am running a Windows 2008 R2 Server for a customer. They have asked me to install PHP Email on the server and I thought I had done that. However they say it's not working. Details are:

PHP 5.4.24 is installed on the server
PHP 5.4.24 (cli) (built: Jan  8 2014 20:26:10)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

SMTP Server is set up and installed using the IIS6 Management Console

PHP is working on the server. Customer is happy that his website calls to PHP are being handled OK. The php.ini variables  tell us that SMTP and smtp_port have the values "localhost" and "25" respectively.

The code he's using:
<?php
error_reporting(E_ALL);
echo 'From ini - SMTP = ' . ini_get('SMTP');
echo ' From ini - port = ' . ini_get('smtp_port');

$to      = 'rks4153@yahoo.co.uk';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$mres = mail($to, $subject, $message, $headers);

// Was accepted?
if ( $mres == '') {
   echo "<p>Result was empty";
   }
else if ( $mres ){
   echo "<p>Result was $mres</p>";
    }
else {
   echo "<p>Message was not accepted</p>";
    };
?>

mail() Is supposed to return true or false (1 or 0). On his live site on an older 2003 server it works fine but on the newer 2008 server we are having this issue.

I have ini_set() set to OFF on the server and not sure whether I need to re-enable it for this process as generally we have errors OFF globally because there are other websites running on the same 2008 server.

Any help would be gratefully accepted.

Cheers
Chris
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris Kenward

ASKER

Hi Dave

Nice to have you answer questions for me again. Appreciate the response. I'll add the telnet client to the unit and try telnetting to the localhost. I don't ever allow the web servers to receive Email from anywhere other than localhost. Once I've done the test I'll report back.

All the best
Chris
Hi Dave

Have checked - the SMTP service was stopped. I added the telnet client feature to the server and managed to telnet to the website. I've now dropped customer an Email asking him to attempt the php mail() thing again and will update you as soon as I hear from him.

Thanks again.
Chris
Good, that explains part of it.
Hi Dave

Just had a reply from customer. Not working. Where do I look now please sir?

Cheers
Chris
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Dave

Yes - the SMTP service is running this morning. I had changed the properties on the Generall tab to reflect the IP address of the server and, when I tried to telnet to localhost from the command prompt, it just hung. I changed the IP address to "All unassigned" and I now get the HELO from the server. WIll get customer to try again.

IP addresses that are allowed to send through the SMTP server are only the IP of the server and 127.0.0.1

Cheers
Chris
Those IP addresses should be adequate for the task.  Do you know how to write a CDO ASP page to send email?  Just another way to test the SMTP server.
Nossir - I have no idea! ;)
Here is a very simple CDO ASP test program.  Put in your own email addresses.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>ASP Email Test</title>
</head>
<body>
<h2>ASP Email Test Using CDO</h2>
<p>Tested and working on 2012-03-23</p>
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.To="you@yourplace.com"
myMail.From="me@myplace.com"
myMail.TextBody="This is a message."
myMail.Send
set myMail=nothing
%>

</body>
</html>

Open in new window

Thanks Dave. Your checks above were what was needed.
You're welcome, glad to help.