1

I've just written my first form using HTML by taking a template for a php emailing form from another site. When I enter all the data, though, it just displays the php page instead of executing the script.

            <form action="template1.php" method="post">
            <p style="padding-top: 5px;" id="form_header">
                Fill out variable information below:
            </p>
            <table width="260px" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td style="padding-top: 14px">
                        Customer name:
                    </td>
                </tr>
                <tr>
                    <td>
                        <input name="toName" type="text" size="45" />
                    </td>
                </tr>
                <tr>
                    <td style="padding-top: 14px">
                        Customer e-mail address:
                    </td>
                </tr>
                <tr>
                    <td>
                        <input name="toEmail" type="text" size="45" />
                    </td>
                </tr>
                <tr>
                    <td style="padding-top: 14px">
                        From name:
                    </td>
                </tr>
                <tr>
                    <td>
                        <input name="fromName" type="text" size="45" />
                    </td>
                </tr>
                <tr>
                    <td style="padding-top: 14px;">
                        From e-mail address:
                    </td>
                </tr>
                <tr>
                    <td>
                        <input name="fromEmail" type="text" size="45" value="[email protected]" />
                    </td>
                </tr>
            </table>
            <table id="reason_boxes" width="260px" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td style="width: 70px; height: 30px;">
                        Reason:
                    </td>
                    <td style="padding: 0 4px 4px 4px; vertical-align: center;">
                        <input type="radio" name="reason" value="credit"/>
                    </td>
                    <td style="padding: 1px 0 4px 4px; vertical-align: center;">
                        Insufficient credit.
                    </td>
                </tr>
                <tr>
                    <td style="padding-top: 14px; width: 70px; height: 100px;">
                    </td>
                    <td style="padding: 4px;">
                        <input type="radio" name="reason" value="credit"/>
                    </td>
                    <td style="padding: 4px;">
                        Software based POS systems and/or Payment Jack processing units do not qualify. We will continue to make enhancements to this service and hope to be able to offer this in the future.
                    </td>
                </tr>
                <tr>
                    <td style="padding-top: 14px; width: 70px; height: 100px;">
                    </td>
                    <td style="padding: 4px;">
                        <input type="radio" name="reason" value="credit"/>
                    </td>
                    <td style="padding: 4px;">
                        Mail order/telephone order and/or internet based business does not qualify. We will continue to make enhancements to this service and hope to be able to offer this in the future.
                    </td>
                </tr>
                <tr>
                    <td style="padding-top: 14px; width: 70px; height: 70px;">
                    </td>
                    <td style="padding: 4px;">
                        <input type="radio" name="reason" value="credit"/>
                    </td>
                    <td style="padding: 4px;">
                        The average ticket requested currently exceeds the parameters established for this program.
                    </td>
                </tr>
                <tr>
                    <td style="padding-top: 14px; height: 50px;">
                    </td>
                    <td style="padding: 4px;">
                    </td>                        
                    <td style="padding: 4px; text-align: right; vertical-align: bottom;">
                        <input name="submit" type="submit" value="Send Email" />
                    </td>
                </tr>
            </table>

And the PHP

    <?php

if(isset($_POST['toEmail'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED 
    $email_to = $_POST['toName'];;
    $email_subject = "This is a test";

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['toName']) ||
        !isset($_POST['toEmail']) ||
        !isset($_POST['fromName']) ||
        !isset($_POST['fromEmail'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $to_name = $_POST['toName']; // required
    $to_email = $_POST['toEmail']; // required
    $from_name = $_POST['fromName']; // required
    $from_email = $_POST['fromEmail']; //  required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  if(!preg_match($email_exp,$to_email)) {
    $error_message .= 'The \'to\' email address you entered for the customer does not appear to be valid.<br />';
  }

  if(!preg_match($email_exp,$from_email)) {
    $error_message .= 'The \'from\' email Address you entered does not appear to be valid.<br />';
  }

    $string_exp = "/^[A-Za-z .'-]+$/";

  if(!preg_match($string_exp,$toName)) {

    $error_message .= 'The first name you entered does not appear to be valid.<br />';

  }

  if(!preg_match($string_exp,$toEmail)) {

    $error_message .= 'The last name you entered does not appear to be valid.<br />';

  }

  if(strlen($error_message) > 0) {

    died($error_message);

  }

    $email_message = "Form details below.\n\n";



    function clean_string($string) {

      $bad = array("content-type","bcc:","to:","cc:","href");

      return str_replace($bad,"",$string);

    }



    $email_message .= "toName: ".clean_string($toName)."\n";

    $email_message .= "toName: ".clean_string($toEmail)."\n";

    $email_message .= "fromName: ".clean_string($fromName)."\n";

    $email_message .= "fromEmail: ".clean_string($fromEmail)."\n";





// create email headers

$headers = 'From: '.$from_name."\r\n".

'Reply-To: '.$from_email."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);  

?>



<!-- include your own success html here -->



Thank you for contacting us. We will be in touch with you very soon.



<?php

}

?>

Thank you!

5
  • 3
    Does your server support PHP and is it properly configured? Commented Apr 26, 2014 at 23:54
  • Nope. I was trying to run it off the desktop and a quick google search revealed that's not going to work. Thank you. =) Commented Apr 26, 2014 at 23:57
  • Yeah that's definitely not going to work Commented Apr 26, 2014 at 23:59
  • Yeah, check out WampServer for a easy install to get you up and going. Commented Apr 27, 2014 at 0:00
  • Had the same problem as well. This tutorial had a quick solution to setting up a server to run php files. Commented Feb 1, 2017 at 2:08

1 Answer 1

1

Seems like your server does not have php installed. If its installed check server settings for mime types. Extension .php needs to be mapped correctly.

Here is an example of setting mime type for extension: Custom MIME Type for PHP File

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.