PHP Undefined index error with form -


i keep getting error follows when submit form. i'm not sure is. i'm running site on wamp (windows) , im writing in dreamweaver cs6. please note i'm new php. thanks!

here code:

notice: undefined index: message in s:\wamp\www\latech\contact.php on line 29

<!doctype html>  <html>  <head>  <meta charset="utf-8">  <?php include 'includes/header.php'?>  <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">  <title>anise technologys</title>  </head>  <body>  <div class="wrapper">  <?php include 'includes/nav.php'?>  <div class="content">  <h1 id="title-center">contact</h1>  		<?php  	  		// check header injections  		function has_header_injection($str) {  			return preg_match( "/[\r\n]/", $str );  		}  		  		  		if (isset($_post['contact_submit'])) {  			  			// assign trimmed form data variables  			// note value within $_post array looking html "name" attribute, i.e. name="email"  			$name	= trim($_post['name']);  			$email	= trim($_post['email']);  			$tel = trim($_post['tel']);  			$msg	= $_post['message']; // no need trim message  		  			// check see if $name or $email have header injections  			if (has_header_injection($name) || has_header_injection($email)) {  				  				die(); // if true, kill script  				  			}  			  			if (!$name || !$email || !$msg) {  				echo '<h4 class="error">all fields required.</h4><a href="contact.php" class="button block">go , try again</a>';  				exit;  			}  			  			// add recipient email variable  			$to	= "brad@brightsidestudios.ca";  			  			// create subject  			$subject = "$name sent message via contact form";  			  			// construct message  			$message .= "name: $name\r\n";  			$message .= "email: $email\r\n\r\n";  			$message .= "message:\r\n$msg";  			  			// if subscribe checkbox checked  			if (isset($_post['subscribe']) && $_post['subscribe'] == 'subscribe' ) {  			  				// add new line $message  				$message .= "\r\n\r\nplease add $email mailing list.\r\n";  				  			}  		  			$message = wordwrap($message, 72); // keep message neat n' tidy  		  			// set mail headers variable  			$headers = "mime-version: 1.0\r\n";  			$headers .= "content-type: text/plain; charset=iso-8859-1\r\n";  			$headers .= "from: " . $name . " <" . $email . ">\r\n";  			$headers .= "x-priority: 1\r\n";  			$headers .= "x-msmail-priority: high\r\n\r\n";  		  			  			// send email!  			mail($to, $subject, $message, $headers);  		?>          		<!-- show success message after email has sent -->  		<h5>thanks contacting anise technologys!</h5>  		<p>please allow 24 hours response.</p>  		<p><a href="/final" class="button block">&laquo; go home page</a></p>   		<?php  			} else {  		?>  <form method="post" action="" id="contact-form" class="pure-form pure-form-aligned">  <div class="pure-control-group">  <label for="name">your name</label>  <input type="text" id="name" name="name" placeholder="name">  </div>  <div class="pure-control-group">  <label for="email">your emal</label>  <input type="email" id="email" name="email" placeholder="you@website.com">  </div>  <div class="pure-control-group">  <label for="tel">your telephone</label>  <input type="tel" id="tel" name="tel" placeholder="(xxx)xxx-xxxx">  </div>  <div class="pure-control-group">  <label for="msg">your message</label>  <textarea id="msg" name="msg" spellcheck="true" ></textarea>  </div>  <div class="pure-control-group">  <label for="subscribe">  <input type="checkbox" id="cb" name="subscribe" value="subscribe">  subscribe newsletter</label>  </div>  <div class="pure-control-group">  <input type="submit" class="pure-button pure-button-primary" name="contact_submit" value="send message">  </div>  </form>  		<?php  			}  		?>  </div>  </div>  </body>  </html><!doctype html>  <html>  <head>  <meta charset="utf-8">  <?php include 'includes/header.php'?>  <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">  <title>anise technologys</title>  </head>  <body>  <div class="wrapper">  <?php include 'includes/nav.php'?>  <div class="content">  <h1 id="title-center">contact</h1>  		<?php  	  		// check header injections  		function has_header_injection($str) {  			return preg_match( "/[\r\n]/", $str );  		}  		  		  		if (isset($_post['contact_submit'])) {  			  			// assign trimmed form data variables  			// note value within $_post array looking html "name" attribute, i.e. name="email"  			$name	= trim($_post['name']);  			$email	= trim($_post['email']);  			$tel = trim($_post['tel']);  			$msg	= $_post['message']; // no need trim message  		  			// check see if $name or $email have header injections  			if (has_header_injection($name) || has_header_injection($email)) {  				  				die(); // if true, kill script  				  			}  			  			if (!$name || !$email || !$msg) {  				echo '<h4 class="error">all fields required.</h4><a href="contact.php" class="button block">go , try again</a>';  				exit;  			}  			  			// add recipient email variable  			$to	= "brad@brightsidestudios.ca";  			  			// create subject  			$subject = "$name sent message via contact form";  			  			// construct message  			$message .= "name: $name\r\n";  			$message .= "email: $email\r\n\r\n";  			$message .= "message:\r\n$msg";  			  			// if subscribe checkbox checked  			if (isset($_post['subscribe']) && $_post['subscribe'] == 'subscribe' ) {  			  				// add new line $message  				$message .= "\r\n\r\nplease add $email mailing list.\r\n";  				  			}  		  			$message = wordwrap($message, 72); // keep message neat n' tidy  		  			// set mail headers variable  			$headers = "mime-version: 1.0\r\n";  			$headers .= "content-type: text/plain; charset=iso-8859-1\r\n";  			$headers .= "from: " . $name . " <" . $email . ">\r\n";  			$headers .= "x-priority: 1\r\n";  			$headers .= "x-msmail-priority: high\r\n\r\n";  		  			  			// send email!  			mail($to, $subject, $message, $headers);  		?>          		<!-- show success message after email has sent -->  		<h5>thanks contacting anise technologys!</h5>  		<p>please allow 24 hours response.</p>  		<p><a href="/final" class="button block">&laquo; go home page</a></p>   		<?php  			} else {  		?>  <form method="post" action="" id="contact-form" class="pure-form pure-form-aligned">  <div class="pure-control-group">  <label for="name">your name</label>  <input type="text" id="name" name="name" placeholder="name">  </div>  <div class="pure-control-group">  <label for="email">your emal</label>  <input type="email" id="email" name="email" placeholder="you@website.com">  </div>  <div class="pure-control-group">  <label for="tel">your telephone</label>  <input type="tel" id="tel" name="tel" placeholder="(xxx)xxx-xxxx">  </div>  <div class="pure-control-group">  <label for="msg">your message</label>  <textarea id="msg" name="msg" spellcheck="true" ></textarea>  </div>  <div class="pure-control-group">  <label for="subscribe">  <input type="checkbox" id="cb" name="subscribe" value="subscribe">  subscribe newsletter</label>  </div>  <div class="pure-control-group">  <input type="submit" class="pure-button pure-button-primary" name="contact_submit" value="send message">  </div>  </form>  		<?php  			}  		?>  </div>  </div>  </body>  </html>

your name attribute msg calling message in php.

<label for="msg">your message</label> <textarea id="msg" name="msg" spellcheck="true" ></textarea>  $msg    = $_post['message']; // no need trim message 

also here...

$message .= "name: $name\r\n";             $message .= "email: $email\r\n\r\n";             $message .= "message:\r\n$msg"; 

the first occurrence should $message = because there nothing concatenate when hasn't been initialized.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -