treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Contact Form not working on windows server

  • I used Chris' simple contact form for a website. It work absolutely fine on my server but when the client uploads it to their server, which is a windows server, its having problems. Instead of redirecting to the Success page, it redirects to the Error page but apparently the recipient is receiving emails. I don't know why or how to stop it from redirecting to the error page, or to stop the error if that's whats happening.

    EDIT: Correction, they are not receiving the emails, which means its not working at all.

    This is the code in the HTML
    <div id=\"contact-area\">

    <form method=\"post\" action=\"contactengine1.php\">
    <label for=\"Name\">Name:</label>
    <br /><input type=\"text\" name=\"Name\" id=\"Name\" />

    <br /><label for=\"Email\">Email:</label>
    <br /><input type=\"text\" name=\"Email\" id=\"Email\" />

    <br /><label for=\"Message\">Message:</label>
    <br /><textarea name=\"Message\" rows=\"20\" cols=\"20\" id=\"Message\"></textarea>

    <br /><input type=\"submit\" name=\"submit\" value=\"Submit\" class=\"submit-button\" />
    </form>

    </div> <!-- End Contact Area -->


    The contact engine
    <?php

    $EmailFrom = \"JHREP Contact Form\";
    $EmailTo = \"mmendiola@jhrep.com\";
    $Subject = \"JH Real Estate Partners, Inc. Contact Form\";
    $Name = Trim(stripslashes($_POST['Name']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Message = Trim(stripslashes($_POST['Message']));

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=error.htm\\">\";
    exit;
    }

    // prepare email body text
    $Body = \"\";
    $Body .= \"Name: \";
    $Body .= $Name;
    $Body .= \"\n\";
    $Body .= \"Email: \";
    $Body .= $Email;
    $Body .= \"\n\";
    $Body .= \"Message: \";
    $Body .= $Message;
    $Body .= \"\n\";

    // send email
    $success = mail($EmailTo, $Subject, $Body, \"From: <$EmailFrom>\");

    // redirect to success page
    if ($success){
    print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=contactthanks.php\\">\";
    }
    else{
    print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=error.htm\\">\";
    }

    ?>


    Chris added a mod by Toni for windows server but I'm not sure if I'm using it correctly.
    /* Modification by Toni for Windows servers */
    ini_set(\"sendmail_from\", \"me@mydomain.co.uk\");


    Should I put it in the contact engine at the end? Also, do I replace "me@mydomain.co.uk" with the Send To email?

    Please help!
  • Ok, I'm going to explain this a little more.

    I built a very simple website for a client using php includes, html, and css. Very simple. The form works fine on my development server.

    I gave it to the client to put on their own server. They're using a Windows server. Everything except the contact form works. He's a IT guy who knows all the server stuff but nothing about PHP or building websites. We're trying to communicate to figure out the problem but we don't know what the other is talking about most of the time. I asked if they use SMTP for their email and he said: "SMTP is not installed but we have an internal exchange server for our email. The websites that we have use this server to connect and send email through. I went ahead and install smtp anyways." Basically, I have no idea what this means and how to make it work.

    The code I showed in the above comment is exactly what's on the website. I guess my main question is: What does he need to do to fix it on his end? Or what do I need to do on my end to fix it?

    Please help if you can! Thank you!
  • Please did anyone resolve this issue, I am having the same problem

  • Not sure if you have already sorted your issue, I have had the exact same problem and been scratching my head for days. I found a fix that works perfectly: (taken from another forum)

    Hi there, Fyi - I found the fix in the php manual, on a forum:

    Under windows there is a bug in php/mail See here: http://bugs.php.net/bug.php?id=28038 this results in you being unable to send 'From: Full Name ' Workaround is: Set the following before calling the mail function:

    ini_set('sendmail_from', 'me@domain.com');

    Hope this helps

    Mark

  • Does the form have any validation? From its demo its seems no.