0

Not sure what is going on here. I am wanting to make a simple e-mail. When the PHP script runs I get three errors:

 Notice: Undefined index: subject
 Notice: Undefined index: email
 Notice: Undefined index: emailcontent

HTML:

<form action="email.php" method="post" class="email-form">
                <input type="text" name="subject" placeholder="E-mail Subject"></input>
                <input type="text" name="email" placeholder="Your E-mail Address"></input>
                <textarea type="text" name="emailcontent"></textarea>
                <br>
                <button type="submit" name="submit" value="send">Send E-mail</button>

</form>

PHP:

<?php

$emailSubject = $_POST["subject"];
$emailAddress = $_POST["email"];
$emailContent = $_POST["emailcontent"];

 $headers = "From: " + $emailAddress;

 $myEmail = "myemail";

 mail($myEmail, $emailSubject, $emailContent, $headers);



 ?>
Namone
  • 121
  • 1
  • 1
  • 10
  • tested your code and it works fine? ... do you have the HTML and PHP in the same file? –  Oct 17 '15 at 03:40
  • I do have them in the same file. – Namone Oct 17 '15 at 04:34
  • if they must be in the same file than wrap the whole all the php code like this `` the `...` is cause i didn't want to type the whole thing –  Oct 17 '15 at 04:35

1 Answers1

1

I think you should first check if fields are set or not. When page loads no value is and a notice is generated

<?php
if(isset($_POST['submit']))
{
    $emailSubject = $_POST["subject"];
    $emailAddress = $_POST["email"];
    $emailContent = $_POST["emailcontent"];

    $headers = "From: " + $emailAddress;

    $myEmail = "myemail";

    mail($myEmail, $emailSubject, $emailContent, $headers);
}



 ?>
Gaurav Rai
  • 900
  • 10
  • 23