0

Hi guys I have a question I am kind of a beginner on PHP so maybe somebody can help me.

I want to create a html contact page but I created already the html.

Now the problem is as you see I am creating a action.php page which I will give the code below but I don't understand why when I did it it appears a 500 error and it says it can not find the action.

But I don't want for my page to go to another page after submitting I want for it to stay on it and just show over the html contact form THANK YOU!

I want the action to be inside the same page index.html or if not possible can I make a action.html page instead reason is because I don't know how to create html inside PHP or at least my DreamWeaver shows me errors.

WHAT AM I AM DOING WRONG?

 <form method="post" action="action.php">
<input type="hidden" name="subject" value="New contact from test website one"> 
<input type="hidden" name="redirect" value="thank-you.html">


<input type="hidden" name="subject" value="New Contact from my website plumbers pro"> 

    <label for="name">Full Name</label>
    <input type="text" name="name" size="30" maxlength="40" autofocus> 
    <br />
    <label for="email">E-mail</label>
     <input type="text" name="email" size="30" maxlength="40" autofocus> 
     <br />
    <label>Message</label>
    <textarea rows="5" name="message" cols="30"></textarea>

    <div class="g-recaptcha" data-sitekey="6LeV8wsUAAAAAAjmdjxK-DG-1AT0jZ16e3tOaxHh"></div>

    <input type="submit" value="Submit" name="request" >
    </form>

HERE IS THE PHP I AM USING

    <?php
if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "markuzdesigns@gmail.com";
    $email_subject = "New Contact from Website example one";


    $first_name = $_POST['name']; // required
    $email_from = $_POST['email']; // required
    $comments = $_POST['message']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do 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 .= "Name: ".clean_string($first_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Message: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" . 
'Bcc: info@EMAIL.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>
Markuz
  • 11
  • 1
  • *"I want the action to be inside the same page index.html or if not possible can I make a action.html page instead"* - PHP doesn't parse "php" directives with `.html` files, if that's what you're trying to do. You need to instruct your server to treat those as php. – Funk Forty Niner Feb 10 '17 at 01:36
  • Possible duplicate of [PHP code is not being executed, instead code shows on the page](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page) – Funk Forty Niner Feb 10 '17 at 01:37
  • Possible duplicate of [PHP mail form doesn't complete sending e-mail](http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – Funk Forty Niner Feb 10 '17 at 01:37

0 Answers0