Simple Mail() Script and an error I never saw before

Hello All:

I have this simple mail script that I wrote about 2 yrs ago.

<?php

// Uncomment the two following lines to test and display errors. Once complete, comment out again.
ini_set ('display_errors', 'On');
error_reporting (E_ALL);

$to = 'email@email.com';
$subject = 'Contact from Website';
$body = 'This information came from your contact us page on your website' . "\\r\
\
\
";

$from = 'contactusform@nebsinc.us';
$body .= 'Name:   ' . $_POST["Name"] . "\\r\
\
\
";
$body .= 'Email Address:   ' . $_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 Email was 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 .</b></font>'; }

}

?>

So basically I am using it for someone else and for some reason I am getting this error and I can’t say that I know what it means.

The error says

Notice: Undefined index: Name in /home/www/nebsinc.us/newsite/contact_form.php on line 16

Notice: Undefined index: email in /home/www/nebsinc.us/newsite/contact_form.php on line 18

Notice: Undefined index: comments in /home/www/nebsinc.us/newsite/contact_form.php on line 20

but these varriables ARE deffined.

What am I missing here with this,

Thanks for any help or advice

Paul

thanks Blake,

I will give this a whirl and see where it takes me…

Paul

Try something like this -

<?php
ob_start();

$cats = array();
$errors = array();
$email_match = "/^[a-zA-Z0-9]+@[a-zA-Z0-9]+[a-zA-Z0-9]+.[a-z]{2,4}$/";
$cats = array(
    "Categories",
    "HTML",
    "CSS",
    "Wordpress",
    "Javascript",
    "Examples of code",
    "Web Development",
    "PSD > HTML & CSS");
    
    
if (isset($_POST['form_submitted'])) {
    if (empty($_POST['name']) || strlen($_POST['name']) < 3)
        $errors[] .= "Name field invalid.";
    
    if (empty($_POST['email']) || strlen($_POST['email']) < 3 || !preg_match($email_match, $_POST['email']))
        $errors[] .= "Email field invalid.";
        
    if (empty($_POST['website']) || strlen($_POST['website']) < 7 || !preg_match("/^[http:\\/\\/]+.+$/", $_POST['website']))
        $errors[] .= "Website field invalid.";
        
    if ($_POST['category'] == $cats[0])
        $errors[] .= "Category not selected.";
        
    if (empty($_POST['comments']))
        $errors[] .= "Please type a message.";
        
    if (empty($_POST['captcha']) || $_POST['captcha'] != 10)
        $errors[] .= "Invalid captcha.";
        
    
    /*** If there are no errors send email ***/
    if (empty($errors)) {
        $message  = "Name: " .$_POST['name']. "\
";
        $message .= "Email: " .$_POST['email']. "\
";
        $message .= "Website: " .$_POST['website']. "\
";
        $message .= "Category: " .$_POST['category']. "\
";
        $message .= "Comments: " .$_POST['message']. "\
";
        $headers = "From: " .$_POST['email']. "\\r\
";
        $headers .= "Content-type: text/html\\r\
";
        $mail = @mail("yourdomain@blah.com", "Work", $message, $headers);
        
        
        if ($mail)
            $message_sent = true;
        else
            die("Unexpected Error");
    }
}

ob_end_flush();
?>
                        
                        <?php if ($message_sent) echo "Email sent" ?>
                        <form method="post" action="contact_us.php">
                            <span class="form_names">Name:</span><br />
                            <input name="name" id="name" class="contact_form" type="text" value="<?=$_POST['name']?>" /><br />
                            
                            <span class="form_names">Email Address:</span><br />
                            <input name="email" id="email" class="contact_form" type="text" value="<?=$_POST['email']?>" /><br />
                            
                            <span class="form_names">Your Website:</span><br />
                            <input name="website" id="website" class="contact_form" type="text" value="<?=$_POST['website']?>" /><br />
                            
                            <span class="form_names">Please choose a Category.</span>
                            
                            <select id="dropdown" name="category">
                                <?php foreach ($cats as $cat): ?>
                                <option value="<?=$cat?>"
                                <?php if ($_POST['category'] == $cat) echo 'selected="selected"'?>><?=$cat?></option>
                                <?php endforeach; ?>
                            </select><br />

                            <span class="form_names">Your Message:</span><br />

                            <textarea name="comments" id="comments" rows="16"><?=$_POST['comments']?></textarea><br />
                            
                            <span class="form_names">What does 5 + 5=?</span><br />
                            <input name="captcha" id="captcha" class="contact_form" type="text" value="" /><br />
                            
                            <input type="hidden" name="form_submitted" id="form_submitted" value="1"/>
                            <input type="submit" id="submit" value="Submit" /><br />
                        </form><!--The end of the form-->
                        
                        <?php if (!empty($errors)): ?>
                           <div id="error_message">
                            <ul>
                                <?php foreach ($errors as $error): ?>
                                <li><?=$error?></li>
                                <?php endforeach; ?>
                            </ul>
                        </div>
                        <?php endif; ?>