Solved

PHP Email not working Windows 2008 R2

Posted on 2015-02-19
12
122 Views
Last Modified: 2015-02-21
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
0
Comment
Question by:kenwardc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40619435
Are you sure the SMTP server is running?  Can you telnet to it and get any response.  Is anything or anyone able to send thru the SMTP server?  Have them try with CDO in ASP.
0
 

Author Comment

by:kenwardc
ID: 40620202
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
0
 

Author Comment

by:kenwardc
ID: 40620270
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
0
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40620298
Good, that explains part of it.
0
 

Author Comment

by:kenwardc
ID: 40620671
Hi Dave

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

Cheers
Chris
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 500 total points
ID: 40620737
Re-check the SMTP service, see if it is responding to telnet.  There is a setting that says what IP addresses it can accept email from.  This is normally a no-brainer.
0
 

Author Comment

by:kenwardc
ID: 40620760
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
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40620768
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.
0
 

Author Comment

by:kenwardc
ID: 40620919
Nossir - I have no idea! ;)
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40621760
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

0
 

Author Comment

by:kenwardc
ID: 40623152
Thanks Dave. Your checks above were what was needed.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40623271
You're welcome, glad to help.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question