0

Firstly, I'm very novice to HTML/CSS/PHP. The problem is that when hitting submit on my contact form, I get the php action code on screen instead of the execution of it.

I have read that this happens when not running the code as local host with php interpreter. The problem here is that I am trying to run my contact form from my web hotel configured as PHP7.4, Apache2.4 UNIX which makes me confused as to why it occurs.

Here is my code,

Contact form

<form id="contact-form" method="post" action="contact-form-handler.php">
<div class="form-control narrow">
    <label for="name">Car</label>
        <input name="car" id="car" placeholder="Audi A3" type="text">
</div>

<div class="form-control narrow">
     <label for="name">Reg</label>
         <input name="reg" id="reg" type="text">
</div>

<div class="form-control narrow">
     <label for="email">Mail</label>
         <input name="email" id="email" type="email">
</div>

<div class="form-control narrow">
     <label for="name">Phone</label>
         <input name="phone" id="phone" type="text">
</div>

<div class="form-control">
    <label for="message">Message</label>
        <textarea name="message" id="message" rows="4"></textarea>
</div>

<ul class="actions">
    <li><input type="submit" value="Send"></li>
</ul>
</form>

The PHP file

<?php
$type = $_POST['type'];
$reg = $_POST['reg'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];   
$message = $_POST['message'];

$email_from = 'name@gmail.com';

$email_subject = "New request";

$email_body = "Type: $type.\n".
    "Reg: $reg.\n".
    "Mail: $visitor_email.\n".
    "Tel: $phone.\n".
    "Msg: $message.\n";

$to = "name2@gmail.com";

$headers = "From: $email_from \r\n";

$headers = "Reply-To: $visitor_email" \r\n";

mail($to,$email_subject,$email_body,$headers);

header("Location: index.html");
?>

Any ideas?

  • Does the file have a ".php" extension? Are you running it through your PHP server? Is your server configured to treat files with a ".php" extension as PHP files? – Wais Kamal Jan 25 '21 at 20:40
  • Yes, it has a .php extension. The code is part of a site published on a domain configured with PHP7.4 and Apache 2.4 if that is what you are asking. – CaribbeanViking Jan 25 '21 at 21:39
  • Check this post: https://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page. It may help. – Wais Kamal Jan 25 '21 at 21:40

0 Answers0