film1201 Posted June 11, 2013 Share Posted June 11, 2013 Here is your test. Below is a simply php for sending an email to yourself and an autoreply to the person filing it out. However, they way it's set up right now, you get the following errorsWarning: mail() [function.mail]: SMTP server response: 550 <customeremail@aol.com> No such user here in E:\inetpub\vhosts\yourdomain.com\httpdocs\test.php on line 56Warning: Cannot modify header information - headers already sent by (output started at E:\inetpub\vhosts\yourdomain.com\httpdocs\test.php:56) in E:\inetpub\vhosts\yourdomain.com\httpdocs\test.php on line 58 Here is the code. Let's see who is the best: <?php $your_email ='ME@mydomain.com';// <<=== update to your email address$autosubject = "Thank you for requesting your Free Quote";session_start();$errors = '';$Name = '';$Email = '';$user_message = '';if(isset($_POST['submit'])){ $Name = $_POST['Name']; $Email = $_POST['Email']; $user_message = $_POST['message']; ///------------Do Validations------------- if(empty($Name)||empty($Email)) { $errors .= "\n Name and Email are required fields. "; } // validate an email addressif( !preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i", $Email) ) { $errors .= "\n You have entered and invalid email address";} if(IsInjected($Email)) { $errors .= "\n Bad email value!"; } if(empty($errors)) { //send the email //send the email $to = $your_email; $subject="there is an email from a customer"; $from = $Email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $message = "This is the message from the customer";$message2 = "This is the message to the customer"; $headers = "From: $from \r\n";$headers .= "Reply-To: $Email \r\n"; $headers2 = "From: Me@mydomain.com"; $headers2 .= "Reply-To: $your-email \r\n"; mail($your_email,"$subject","$message","From: $Name <$Email>\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1");mail($from, $autosubject, $message2, "From: Me <$your_email>\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1");header('Location: http://www.mydomain.com/thank-you.html'); }}// Function to validate against any email injection attemptsfunction IsInjected($str){ $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; }}?> <!DOCUTYPE Html><html><head></head><body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0"><?phpif(!empty($errors)){echo "<p class='err'>".nl2br($errors)."</p>";}?></div><style type="text/css">.blueBoxText{ line-height:120%; font-size:12px; font-family:Arial, Verdana, Helvetica, sans-serif; }</style><form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <table> <tr><td class="blueBoxText" align="left" valign="top"><label for='Name'>Name: </label></td></tr> <tr><td align="left" valign="top"><input type="text" name="Name" value='<?php echo htmlentities($Name) ?>' style="background-color: rgb(255, 255, 160)"></td></tr> <tr><td class="blueBoxText" align="left" valign="top"><label for='Email'>Email: </label></td></tr> <tr><td align="left" valign="top"><input type="email" name="Email" value='<?php echo htmlentities($Email) ?>' style="background-color: rgb(255, 255, 160)"></td></tr><tr><td align="left" valign="top"><input type="submit" value="Submit" name='submit'></td></tr></table></form> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/279026-i-have-a-php-challenge-lets-see-who-can-find-the-solution-first/ Share on other sites More sharing options...
requinix Posted June 11, 2013 Share Posted June 11, 2013 @-suppress mail() and check its return value. Oh, and Let's see who is the best:Trying to trick us into solving your problem by phrasing it as some sort of "contest" is insulting. There's nothing wrong with asking people for help if you don't know the answer. Quote Link to comment https://forums.phpfreaks.com/topic/279026-i-have-a-php-challenge-lets-see-who-can-find-the-solution-first/#findComment-1435288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.