0

I have a very simple contact form on my website, but unfortunetly it's not working at all.

What's going on is that when I click "submit" button, the site is becoming blank and the mail is not beeing sent to my inbox (I do not use gmail).

Code:

PHP:

    <?php

if(isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $topic = $_POST['topic'];
    $message = $_POST['message'];
    
    $mailTo = "xxxx@yyyy.zz";
    $headers = "From: ". $email;
    $txt = "You've received a message from: ".$name.".\n"."Subject: ".$topic."\n\n".$message;   
    
    mail($mailTo, $topic, $txt, $headers);
    //header("Location: index.pxp?mailsend");
}

?>

HTML:

<form method="post" class="contact-form" action="contactform.php">
  <label for="name">Full name</label>
  <input type="text" name="name" id="name"  placeholder="Full name *" required>

  <label for="email">Email</label>
  <input type="text" name="email" id="email"  placeholder="example@example.com *" required>
  
  <label for="topic">Subject</label>
  <input type="text" name="topic" id="topic"  placeholder="Subject *" required>

  <label for="message">Message</label>
  <textarea name="message" id="message"  placeholder="Enter your message here" required></textarea>
  
  
  <input class="submit_button" type="submit" name="submit" value="Submit" onclick="Submitting_error()">
</form>

Can someone explain to me why the contact form is not working, and if you're willing to help additionally, can You fix my php (and if needed, html) code?

I added this onclick funtction to let user know that contact form is not working now onclick="Submitting_error()" after the problem is resolved I'll remove this.

Thanks in advance :)

  • Is the form getting submitted? Try adding `echo "form submitted";` after `if(isset(...` to check that. – Wais Kamal Sep 06 '20 at 09:42
  • Yes, its getting submitted. URL looks like this http://www.domain.lang/contactform.php The echo is working, but still, the page is blank. I honestly I don't get it why browser is trying to open .php file as site source file. – Jakub Szurlej Sep 06 '20 at 09:52
  • Alright. It seems that my contact form works, but because email were succesfully sent to my other email adress. So probably theres smth with spam filters. – Jakub Szurlej Sep 06 '20 at 10:52

0 Answers0