Solved

PHP Email not working Windows 2008 R2

Posted on 2015-02-19
12
116 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
  • 6
  • 6
12 Comments
 
LVL 82

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
 
LVL 82

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 82

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
Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

 

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 82

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 82

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 82

Expert Comment

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now