Notice: Undefined index:?

Hello,

I am kind of new to php and was wondering if someone can tell me what I am doing wrong with this mail script.

I have my form action set to this script on my server:

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

if (!preg_match("/\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*/", $email)) {
  echo "<h4>Invalid email address</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($comments == "") {
  echo "<h4>Please Leave Us some Comments</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

$to = 'pmsquillace@gmail.com';
$subject = 'Comments From the NEBS Website';
$body = 'These are comments that were filled out your form on your website' . "\\r\
\
\
";

$from = 'onlineform@nebsinc.com';

$body .= 'Name:   ' . $_POST["name"] . "\\r\
\
\
";

$body .= 'Email:   ' . $_POST["email"] . "\\r\
\
\
";

$body .= 'Comments:   ' . $_POST["comments"] . "\\r\
\
\
";


if(isset($_POST['submit'])){

$mailsent = mail($to,$subject,$body,$from);

if($mailsent){ 

    echo '<font color="#ff0000"><b>Your Comments were Sent Successfully! We will be in touch with you soon!</b></font>'; 
    
    } else { 
    
    echo '<font color="#ff0000"><b>There was a problem sending this to our office, please call us at 631.249.2260.</b></font>'; }
}
?>

When I submit the form, I get the following error:

[B]Notice[/B]:  Undefined index:  name in [B]/home/www/nebsinc.us/newsite/contact_form.php[/B]  on line [B]29[/B]

[B]Notice[/B]:  Undefined index:  email in [B]/home/www/nebsinc.us/newsite/contact_form.php[/B]  on line [B]31[/B]

[B]Notice[/B]:  Undefined index:  comments in [B]/home/www/nebsinc.us/newsite/contact_form.php[/B]  on line [B]33[/B]

I know I can easily suppress this error I am getting by changing the first line or editing my php.ini but I want to learn what the problem is and if there is a solution to fix it.

Thanks for any help or advice,

Paul

Thanks PHPycho,

I figured it out, The problem was that I did not have the php in the same page as the form and it was looking for those inputs on that page to send the data.

Sooooo,

Thanks for the help though,

Paul

It’s obvious that you are not getting post values.
try

print_r($_POST);

for debugging