0

Can someone help do fix this, it always says unidentified index and variable. is the script getting the data from the text field ? I am trying to send an email from website but this keep on showing and cannot send an email

   <?php

         $to ='jasoncas02@yahoo.com.ph';    
         $subject = 'Customer Inquiry';            

         $name = $_POST['name'];             
         $email = $_POST['email'];
         $tel = $_POST['tel'];
         $message = $_POST['message'];

         $body = <<<EMAIL
            Hi! My name is $name.
         $message

         from: $name 
         $email
         $tel

         EMAIL;

         $header = "from:$email";

         if($_POST){
         if($name == ' ' || $email == ' ' || $message == ' '|| $tel == ' '){$feedback = 'Fill out all the fields';
         }
         else{

         mail($to, $subject, $body, $header);
         $feedback = "Thanks for you Email, We will answer your email as soon as possible";
         }
         }

         ?>
         <!DOCTYPE HTML>
         <html>
         <head>
         <title></title>
         <link rel="shortcut icon" href="pic/icon.png">
         <meta charset="utf-8">
         <!-- Google Fonts -->

         <!-- CSS Files -->
         <link rel="stylesheet" type="text/css" media="screen" href="style.css">
         <link rel="stylesheet" type="text/css" media="screen" href="menu/css/simple_menu.css">
         </head>
         <body>
         <div id="container">
           <h1>Contact Us</h1>
           <h2>Send Email</h2>
          <p id="feedback"><?php echo $feedback; ?></p>
             <form action="?" method="post">
            <ul>                
            <li>
               <label for=" name"><strong><font size="+2">Name:</font></strong></label>
               <input name="name" id="name" type="text"><br><br>
            </li>
             <li>
              <label for="tel"><strong><font size="+2">Telephone: </font></strong></label>
                 <input name="tel" id="telephone" type="text"><br><br>
               </li>
              <li>
                 <label for="email"><strong><font size="+2">Email: </font></strong></label>
                 <input name="email" id="email" type="email"><br><br>
              </li>
              <li>
                 <label for="message"><strong><font size="+2">Message: </font></strong></label>
                 <textarea rows="9" cols="42" name="message" id="message"></textarea><br>
            </li>

              <li>
                 <input value="Submit" type="submit">

             </li>
             </ul>
             </form>
             enter code here
           </div>
           </body>
           </html>
Not a bug
  • 4,286
  • 2
  • 40
  • 80

2 Answers2

0

make your $body variable like this

 $body = "
          Hi! My name is ".$name."<br/>"
          ".$message."<br/>

         from: ".$name."<br/>" 
         .$email."<br/>"
         .$tel."<br/>"

          ";
Satish Sharma
  • 9,547
  • 6
  • 29
  • 51
0

Check $_POST before using it.

if(!empty($_POST) && isset($_POST['name']) && isset($_POST['tel']) && isset($_POST['email']) && isset($_POST['message'])){
//send mail code
}
pratik nagariya
  • 574
  • 5
  • 21
  • Notice: Undefined index: on line 18 Notice: Undefined index: on line 19 Notice: Undefined index: on line 20 Notice: Undefined index: on line 21 Notice: Undefined variable: feedback in C:\xampp\htdocs\88 hotspring resort\trial.php on line 60 it's the same. still unidentified index and variable – user3580448 Apr 28 '14 at 09:38