-1

I'm new to PHP and having a hard time getting the PHP to mail when the contact form is filled out and submit is pressed. I've posted the PHP and HTML files. Any help is very much appreciated.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Jaza Solutions - Contact</title>
    <link rel = "stylesheet"
    type = "text/css"
    href = "jazasolutions.css" /> 
</head>
<body>
    <div id = "header">
        <img src="jazasolutions.png" alt = "Jaza Solutions, LLC">
    </div>
    <div id="nav">
        <ul>
            <li><a href=JazaSolutionsContact.html>Contact</a></li>
            <li><a href=JazaSolutionsAboutUs.html>About Us</a></li>
            <li><a href=JazaSolutionsCourses.html>Courses</a></li>
            <li><a href=JazaSolutions.html>Home</a></li>
        </ul>
    </div>
    <div class="sideRight">
        <p> Jaza Solutions</p>
        <p> 9818 Ushers Place </p>
        <p> Waldorf, MD 20601 </p>
        <br>
        <p>301-861-2133</p>
        <p>info@jazasolutions.com</p>
    </div>
    <div class = "main">
        <p>  Get the Management Certification you need to make the next step in your career! </p>
        <br>
        <p>SEND A MESSAGE</p>   
        <form class="contact-form" action="contactform.php" method="post">;
            <input type="text" name="name" placeholder="Full Name">
            <input type="text" name="mail" placeholder="Email">
            <input type="text" name="subject" placeholder="Subject">
            <textarea name="message" placeholder="Message"></textarea>
            <button type="submit" name="submit">SEND MAIL</button>
        </form>
    </div>
</body>
</html>   

The PHP code is posted here. This should send an email, but I can't figure out why it's not working.

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

    $mailTo = "pmckeown@jazasolutions.com";
    $headers = "From:  ".$mailFrom;
    $txt = "You have received an email from ".$name.".\n\n".$message;

    mail($mailTo, $subject, $txt, $headers);
    header("Location: index.php?mailsend");
}
?> 
Vince
  • 5
  • 6
  • 1
    Possible duplicate of [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – iainn Mar 14 '18 at 20:15
  • I was able to find one error, but it still isn't working. I have a ; after
    ;
    – Vince Mar 14 '18 at 20:20
  • You should also be aware that your code is very prone to abuse. Someone could spam your Mail-Account (using a bot or just script). – Alex Mar 14 '18 at 20:23
  • I found a similar problem on another thread and tried changing mail($mailTo, $subject, $txt, $headers); to mail("$mailTo", "$subject", "$txt", "$headers"); it still didn't solve the problem. – Vince Mar 14 '18 at 20:26
  • `phpMailer` ??? I see no phpMailer code here. Do you actually have a mail server configured? `mail()` does not actually send mail, it just passed it on to a mailserver to do all the work. No Mailserver === no mail sent – RiggsFolly Mar 14 '18 at 21:17
  • RiggsFolly, thank you. I do not have a Mailserver set up. I was assuming mail() would actually send the email. – Vince Mar 14 '18 at 21:58

1 Answers1

1

I tried something similar a few years ago. After hours of searching I got a Tipp I'll never forget. The Mail RFC is so huge and has so many special cases that you don't do yourself a favor when you try to implement this on your own (Even if you get your Mail send it's most likely that it will be marked as spam from most of the Mail-Services out there because you missed some special handling or some tags). This becomes really funny when you try to send an attachment or even images in your mailer implementation. I'd recommend you try one of the proven Mail-Libraries for PHP like PHPMailer. You can expect that most of the common use-cases work out of the box without great problems.

Alex
  • 1,857
  • 3
  • 36
  • 51