0

I'm quite new to coding in general and JUST started trying to use PHP for a uni project.

I've made an extremely easy HTML contact form, and haven't bothered styling it (as it's just a test) My problem is now, that I've tried to get it actually send an email via. PHP. The contact form itself works, but it just doesn't send an email to the mail I've chosen in PHP

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title> Contact form tutorial </title>
</head>

<body>
  <main>
    <p> SEND E-MAIL </p>
    <form class="contact-form" action="contactform.php" method="post">
      <input type="text" name="name" placeholder="Full name">
      <input type="text" name="mail" placeholder="Your e-mail">
      <input type="text" name="subject" placeholder="Subject">
      <textarea name="message" placeholder="Message"></textarea>
      <button type="submit" name="submit"> SEND MAIL </button>
    </form>
  </main>
</body>

</html>

<?php

if (isset($_POST['submit'])) {
  $name = $_POST['name'];
  $subject = $_POST['subject'];
  $mailFrom = $_POST['mail'];
  $message = $_POST['message'];

  $mailTo = "hse-g01@haarslev-esport.dk";
  $headers = "From: ".$mailFrom;
  $txt = "You have recieved an e-mail from ".$name.".\n\n".$message;

  mail($mailTo, $subject, $txt, $headers);
  header("Location: index.html?mailsend");
}
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Tmptvk
  • 1
  • 3
  • 1
    Welcome to Stack Overflow! Please visit [help], take [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output. Post CODE. Not PICTURES of code – mplungjan Mar 05 '20 at 13:06
  • Please dont post pictures of code. Post the actual code using copy/paste – RiggsFolly Mar 05 '20 at 13:06
  • 1
    Also NEVER call anything in a form "submit". If you ever want to programatically submit a form you will not succeed – mplungjan Mar 05 '20 at 13:07
  • Is your PHP installation configured to send e-mails? – Noah Boegli Mar 05 '20 at 13:08
  • _Small note_ You do know that a $var placed in a double quotes string literal will automatically expand that variable? Makes code easier to read as well – RiggsFolly Mar 05 '20 at 13:09
  • 1
    Do you actually have a mail Server on your system? The `mail()` function does not actually send email it just passes it to a mail server for onward transmittion – RiggsFolly Mar 05 '20 at 13:10

0 Answers0