Link to home
Start Free TrialLog in
Avatar of benners70
benners70

asked on

IIS7 SMTP PHP Email Problem

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.

php.ini
[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?


<%
Err.Clear
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
mail.Send
set mail = nothing

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


<?php
if(mail('test@hotmail.co.uk','test subject','test message')){
      echo('ok');
    }
else{
     echo('not ok');
    }
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of zvytas
zvytas
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of benners70
benners70

ASKER

What should I be replacing me@example.com with?
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".
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 =
Try to add the following at the top of your php code:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

This might show some details about the error. If it doesn't I think the only way to debug is checking the log files.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Hello,

That's what I stated under my post.