We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25322
    • 78 Posts
    Hi I am about to start integrating modx into a site in the next couple of weeks so this isn’t really a modx problem but you guys are so good at helping out I can’t think of a better place to ask.. I have been asked to try get a php enquiry form running asap on the site before I start integrating modx. I will more than likely use the eform snippet for this.
    I have done a quick testing php enquiry form on my own server from dreamhost which works fine. Code is below. I have then uploaded the form to the live site which runs on someone elses apache server and it does nothing. looks as though its sent the form but I never receive any email.
    I have ran info.php on both sites which can be viewed here:

    my server were the form runs fine http://www.testphp.dreamhosters.com/info.php
    other server were it doesn’t work http://www.seafairhaven.org.uk/info.php

    enquiry form code
    form.html

    <form method="POST" action="contact.php">
    Fields marked (*) are required

    <p>Email From:*

    <input type="text" name="EmailFrom">
    <p>Subject:

    <input type="text" name="Subject">
    <p>BoatName:

    <input type="text" name="BoatName">
    <p>BoatType:

    <input type="text" name="BoatType">
    <p>LOA:

    <input type="text" name="LOA">
    <p>Name:

    <input type="text" name="Name">
    <p>Address:

    <input type="text" name="Address">
    <p>Town:

    <input type="text" name="Town">
    <p>PostCode:

    <input type="text" name="PostCode">
    <p>Country:

    <input type="text" name="Country">
    <p>Tel:

    <input type="text" name="Tel">
    <p>Email:

    <input type="text" name="Email">
    <p><input type="submit" name="submit" value="Submit">

    </form>


    contact.php

    <?php


    // get posted data into local variables
    $EmailFrom = Trim(stripslashes($_POST[’EmailFrom’]));
    $EmailTo = "[email protected]";
    $Subject = Trim(stripslashes($_POST[’Subject’]));
    $BoatName = Trim(stripslashes($_POST[’BoatName’]));
    $BoatType = Trim(stripslashes($_POST[’BoatType’]));
    $LOA = Trim(stripslashes($_POST[’LOA’]));
    $Name = Trim(stripslashes($_POST[’Name’]));
    $Address = Trim(stripslashes($_POST[’Address’]));
    $Town = Trim(stripslashes($_POST[’Town’]));
    $PostCode = Trim(stripslashes($_POST[’PostCode’]));
    $Country = Trim(stripslashes($_POST[’Country’]));
    $Tel = Trim(stripslashes($_POST[’Tel’]));
    $Email = Trim(stripslashes($_POST[’Email’]));

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

    // prepare email body text
    $Body = "";
    $Body .= "BoatName: ";
    $Body .= $BoatName;
    $Body .= "\n";
    $Body .= "BoatType: ";
    $Body .= $BoatType;
    $Body .= "\n";
    $Body .= "LOA: ";
    $Body .= $LOA;
    $Body .= "\n";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Address: ";
    $Body .= $Address;
    $Body .= "\n";
    $Body .= "Town: ";
    $Body .= $Town;
    $Body .= "\n";
    $Body .= "PostCode: ";
    $Body .= $PostCode;
    $Body .= "\n";
    $Body .= "Country: ";
    $Body .= $Country;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $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=index.html\">";
    }
    else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    }
    ?>



    Cheers if anyone can help me.
      • 4626
      • 57 Posts
      Do you come to the error.html-page, to the index.html-page or do you receive a blank page?

      And why do you:
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";

      It’s probably better to do a header-redirect i.e.:
      header("Location: http://www.seafairhaven.org.uk/error.html");
      exit;


      Also note that you have written two different error-pages: error.htm, and error.html

      It’s a lot easier to diagnose if you explain exactly what happens when you try to send and a easy way to check where something goes wrong is to insert echo ’step 1’; etc so you know how far the script has run before dieing.
        • 33372
        • 1,611 Posts
        Can you get the mail function to work at all on this server using a simple one-line script? If not, you may need to talk to whomever it is that set up that Apache server and get them to set up mail correctly. Also: You likely need to add the -f parameter in order to forcibly change the sender address to something other than the default PHP mailer account (see http://www.php.net/manual/en/function.mail.php for more info).
          "Things are not what they appear to be; nor are they otherwise." - Buddha

          "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

          Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options