-2

I've looked everywhere on the web and I can't find a solution to my mail function. I've used xampp localhost and ive uploaded to a domain with no results.

My PHP code is:

<?php
    //Grab from html form
    $email = $_POST["email"];
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    $error = "";
    //check if fields are filled
    if (empty($subject)) {
        $error = "Enter a subject";
    }
    if (empty($message)) {
        $error .= "Enter a message";
    }
    echo $error;

    //send email
    mail($email, $subject, $message);
?>

The html code is below just in case...

<!DOCTYPE HTML>
<html>
<head>
    <meta charset= "utf-8">
</head>
<body>
    <form action="serverCode/mail.php" method="post">
        Subject: <input type="text" name="subject"><br>
        From: <input type="text" name="from"><br>
        From Email: <input type="text" name="fromEmail"><br>
        Message: <input type="text" name="message"><br>
        To Email: <input type="text" name="email"
        <input type="submit" value="Submit">
    </form>
</body>
</html>

I'm just trying to make a simple webmailer in PHP.

ffflabs
  • 17,166
  • 5
  • 51
  • 77
ETurns
  • 73
  • 1
  • 12
  • For some reason its cutting out my php code. Here it is again – ETurns Feb 16 '15 at 01:12
  • and the symptom is that you aren't receiving anything on your test address, right? Have you tried using mail at the console to see if the machine is capable of sending mail? PHP would delegate on the system under the hood, so there's that. – ffflabs Feb 16 '15 at 01:15

2 Answers2

1

It's probably due to a bad PHP configuration (specially if you are running XAMPP on Windows) or missing email headers. That was already asked many times. Check these links:

How to send an email using PHP?

php mail setup in xampp

Community
  • 1
  • 1
Mdarc
  • 56
  • 4
0

Your HTML markup is incorrect:

The <input> element with the name "email" does not have a closing tag:

To Email: <input type="text" name="email"

seanlevan
  • 1,367
  • 3
  • 15
  • 33