?
Solved

PHP Email not working Windows 2008 R2

Posted on 2015-02-19
12
Medium Priority
?
123 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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
LVL 84

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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 2000 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 84

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 84

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 84

Expert Comment

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

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
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).
Suggested Courses

764 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