[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


IIS7 SMTP PHP Email Problem

Posted on 2011-09-06
Medium Priority
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.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

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    = "admin@mydomain.com" & "(Senders Name)"
mail.Subject = "TEST ASP"
mail.To      = "test@hotmail.co.uk"
'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@hotmail.co.uk','test subject','test message')){
     echo('not ok');

Open in new window

Question by:benners70
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
  • 4
  • 3
  • 2

Accepted Solution

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

sendmail_from = me@example.com

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

Author Comment

ID: 36488766
What should I be replacing me@example.com 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 "admin@mydomain.com".
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.


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 = mail.mydomain.co.uk
smtp_port = 25

; For Win32 only.
sendmail_from = website@mydomain.com
auth_username = website@mydomain.com
auth_password = mydomainpassword

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;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 =

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 1000 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 = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$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 <noreply@technodg.com>";
$to = "name Recipient <logswatch@yahoo.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "hostname";
$username = "test@domain.com";
$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 = admin@yourdomain.com
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: admin@yourdomain.com' ;
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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…
Suggested Courses

656 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