Announcement

Collapse
No announcement yet.

Help: IIS 6.0 ASHX or PHP extension

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help: IIS 6.0 ASHX or PHP extension

    Hi it's been a while since I laid my hands on IIS 6.0 on windows 2003 Server SP2. I am trying to run a MailHandler.php or MailHandler.ashx for a small business site that has a web form.

    I currently have exchange 2003 running on the server. I'd like to have the server run either extensions. Can someone point into the right direction? Thank you

    PHP Code:
    <?php
    $owner_email = $_POST["owner_email"];
    $headers = 'From:' . $_POST["email"];
    $subject = 'A message from your site visitor ' . $_POST["name"];
    $messageBody = "";

    $messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
    $messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
    $messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
    $messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";

    if($_POST["stripHTML"] == 'true'){
    $messageBody = strip_tags($messageBody);
    }

    try{
    if(!mail($owner_email, $subject, $messageBody, $headers)){
    throw new Exception('mail failed');
    }else{
    echo 'mail sent';
    }
    }catch(Exception $e){
    echo $e->getMessage() ."\n";
    }
    ?>

    ASHX:
    <%@ WebHandler Language="C#" Class="Handler" Debug="true" %>

    using System;
    using System.Web;
    using System.Net.Mail;
    using System.Text.RegularExpressions;

    public class Handler : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
    SmtpClient mailClient = new SmtpClient(context.Request.Form.Get("localhost"));
    string owner_email = context.Request.Form.Get("owner_email");
    string subject = "A message from your site visitor " + context.Request.Form.Get("name");
    string email = context.Request.Form.Get("email");
    string messageBody = "";

    messageBody += "<p>Visitor: " + context.Request.Form.Get("name") + "</p>\n";
    messageBody += "<br>\n";
    messageBody += "<p>Email Address: " + context.Request.Form.Get("email") + "</p>\n";
    messageBody += "<br>\n";
    messageBody += "<p>Phone Number: " + context.Request.Form.Get("phone") + "</p>\n";
    messageBody += "<br>\n";
    messageBody += "<p>Message: " + context.Request.Form.Get("message") + "</p>\n";


    MailMessage message = new MailMessage();

    try{
    message.From = new MailAddress(email.ToString());
    }catch (FormatException e) {
    context.Response.Write(e.Message);
    }

    message.To.Add(owner_email);
    message.Subject = subject;
    if(context.Request.Form.Get("stripHTML") == "true"){
    message.IsBodyHtml = false;
    messageBody = Regex.Replace(messageBody, "<.*?>", string.Empty);
    }else{
    message.IsBodyHtml = true;
    }
    message.Body = messageBody;

    try{
    mailClient.Send(message);
    }catch (SmtpException e) {
    context.Response.Write("mail failed");
    }
    context.Response.Write("mail sent");
    }

    public bool IsReusable {
    get {
    return false;
    }
    }
    }

  • #2
    Re: Help: IIS 6.0 ASHX or PHP extension

    PHP does not come natively with IIS -- it must be installed:
    https://www.google.co.uk/search?q=in...a&channel=fflb

    ASHX should be handled already: http://msdn.microsoft.com/en-us/libr...vs.100%29.aspx
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Help: IIS 6.0 ASHX or PHP extension

      i got the extension to work. Now I cant get the SMTP to work on the localhost. I dont see any logs of it denying the access to relay the msgs. I told SMTP to allow anonymous logins on the localhost only.

      Any ideas?

      Comment


      • #4
        Re: Help: IIS 6.0 ASHX or PHP extension

        This guide helped
        http://youtu.be/ANRpnDMsGcQ

        Comment

        Working...
        X