IIS7 SMTP PHP Email Problem

Posted on 2011-09-06
Last Modified: 2012-05-12
I'm running a dedicated Windows Web Server 2008 R2 Service Pack 1.

I can send email fine using an ASP script (attached) but can't send email via a PHP script (attached).

I have MailEnable installed but the SMTP service for this is disabled. If I disable the Windows SMTP service all mail gets saved to C:\inetpub\mailroot\Pickup so I feel confident the Windows SMTP service is being used. I've looked at the configuration options for SMTP in IIS Manager but any change I make here to Default Web Site or the test URL's site don't seem to affect the SMTP service.

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from =

Does anyone have any suggestions? Is there somewhere else I can configure SMTP?

On Error Resume Next

Set mail 	 = Server.CreateObject ("CDONTS.NewMail")
mail.From    = "" & "(Senders Name)"
mail.Subject = "TEST ASP"
mail.To      = ""
'Text format
mail.BodyFormat = 0
'Mime format
mail.MailFormat = 0
mail.Body = body
set mail = nothing

If Err.Number <> 0 Then
  Response.Write (Err.Description& "<br><br>")  
   Response.Write("Mail Sent" & vbCrLf)
End If
On Error GoTo 0

if(mail('','test subject','test message')){
     echo('not ok');

Open in new window

Question by:benners70
  • 4
  • 3
  • 2

Accepted Solution

zvytas earned 250 total points
ID: 36488720
Try to uncomment the following line in the php.ini:

sendmail_from =

This line is required when running sending mail from php on Windows.

Author Comment

ID: 36488766
What should I be replacing with?

Expert Comment

ID: 36489206
Whatever you want to be a sender of the email, if you want it exactly the same as asp version you should use "".

Author Comment

ID: 36489325
I think the solution is in the php.ini file. I currently have the following which isn't working. I've tried to set ip up to use an SMTP service on a shared server I use which requires authentication as I can't seem to use localhost.

I also don't get an helpfull errors from by PHP mail test script, is there something I can do to get something useful back?

[mail function]
; For Win32 only.
smtp_port = 25

; For Win32 only.
sendmail_from =
auth_username =
auth_password = mydomainpassword

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On

; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.


Expert Comment

ID: 36489446
Try to add the following at the top of your php code:

ini_set('display_errors', 1);

This might show some details about the error. If it doesn't I think the only way to debug is checking the log files.

Assisted Solution

vaibhavjaiman earned 250 total points
ID: 36496317

You are using port 25 for relaying the mail from the IIS SMTP which would be conflicting with the Mailenable SMTP services,You can try telnet to the port 25 and you will know it,

What you require is that please change the SMTP port under the php.ini to 2525 and there after make sure that you have configured the IIS SMTP to relay the mail from the server using that port.
IIS7 uses the IIS6 SMTP virtual server to relay mail.

Further you can use the below simple script to relay mail through localhost
$to = "";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "";
$headers = "From:" . $from;
echo "Mail Sent.";
Alternatively,You can use the authenticated script to  send the mail from PHP,Below is the sample script,In order to make the below script work you need to install the pear package including mail,Auth,net_smtp pear package
require_once "Mail.php";

$from = "name Sender <>";
$to = "name Recipient <>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "hostname";
$username = "";
$password = "N%Kx.p7vULSN";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");

Assisted Solution

benners70 earned 0 total points
ID: 36496786
HI vaibhavjaiman

Thanks for the suggestions which are useful. I have however had to pay for support from my provider to resolve this quicker.

The solution was as follows:
1. Disable all components of MailEnable to ensure no comflict.
2. Open IIS6 to adminster the Relay setting under the Access tab. Add in and also localhost. This last value was probably the root of the problem.
3.php.ini as follows. As far as I can tell sendmail_from can be any email.

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
sendmail_from =
4. Restart IIS.

Other useful things.
1. To send via external SMTP with authentication in PHP you need to install PEAR.
2. To help avoid spam folders set 'sendmail_from' to be the same as the Reply-To. e.g.
$headers .= 'Reply-To:' ;
mail($to, $subject , $body, $headers

Author Comment

ID: 36500921
I've requested that this question be closed as follows:

Accepted answer: 0 points for benners70's comment http:/Q_27292675.html#36496786

for the following reason:

I have accepted my own solution as it is the solution.

Expert Comment

ID: 36500922

That's what I stated under my post.

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do write this URL Rewrite Rule for IIS 3 75
Prevent spoofed emails for Office 365 customer 4 45
Creating a reverse DNS record 3 53
change default ports in Postfix 1 15
MS outlook is a premier email client that enable you to send and receive the e-mails with various file formats of attachments such as document files, media file, and many others formats. There is some scenario occurs when a receiver of an e-mail mes…
Import PST to Exchange using Power Shell new-mailboximportrequest command, you can simply import the PST file into Exchange mailbox or archived. To know How to import PST into Exchange  2013 read the complete article.
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

932 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

10 Experts available now in Live!

Get 1:1 Help Now