danielbala Posted May 3, 2012 Share Posted May 3, 2012 Hi. Iam trying to sent this form values to my email Its not working Can anyone help to solve this.. this is the form <form method="POST" action="sendemail.php"> <table width="450px"> <tr> <td valign="top"> <label for="name">Name </label> </td> <td valign="top"> <input type="text" name="name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="organisation">Organisation </label> </td> <td valign="top"> <input type="text" name="organisation" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="contact">Contact no </label> </td> <td valign="top"> <input type="text" name="contact" maxlength="80" size="30"> </td> </tr> <tr> <td valign="top"> <label for="remarks">Remarks</label> </td> <td valign="top"> <textarea name="remarks" maxlength="50" ></textarea> </td> </tr> <tr> <td valign="top"> <label for="designation">Designation </label> </td> <td valign="top"> <input type="text" name="designation" maxlength="50" size="50"> </td> </tr> <tr> <td valign="top"> <label for="email">E-mail </label> </td> <td valign="top"> <input type="text" name="email" maxlength="50" size="40"> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </td> </tr> </table> </form> sendemail.php <?php session_start(); if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "Contact Details"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['organisation']) || !isset($_POST['email']) || !isset($_POST['contact']) || !isset($_POST['designation']) || !isset($_POST['remarks'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; $organisation = $_POST['organisation']; $email = $_POST['email']; $contact = $_POST['contact']; $designation = $_POST['designation']; $remarks = $_POST['remarks']; $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'Name you entered does not appear to be valid.<br />'; } if(strlen($remarks) < 2) { $error_message .= 'The Remarks you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Organisation: ".clean_string($organisation)."\n"; $email_message .= "Contact No: ".clean_string($contact)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Remarks: ".clean_string($remarks)."\n"; $email_message .= "Designation: ".clean_string($designation)."\n"; $headers = 'From: '.$email."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); }?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. Quote Link to comment https://forums.phpfreaks.com/topic/261998-email-is-not-sent/ Share on other sites More sharing options...
runnerjp Posted May 3, 2012 Share Posted May 3, 2012 Hello, Quick look at the code and you need to chnage function died($error) { to function die($error) { This should show you where the code is showing the error. Quote Link to comment https://forums.phpfreaks.com/topic/261998-email-is-not-sent/#findComment-1342607 Share on other sites More sharing options...
Jessica Posted May 3, 2012 Share Posted May 3, 2012 Hello, Quick look at the code and you need to chnage function died($error) { to function die($error) { This should show you where the code is showing the error. *buzzer sound* You cannot override existing PHP functions. As for the problem, "it's not working" is useless to us. Quote Link to comment https://forums.phpfreaks.com/topic/261998-email-is-not-sent/#findComment-1342722 Share on other sites More sharing options...
batwimp Posted May 3, 2012 Share Posted May 3, 2012 Can you give more detail on how it's not working? Are you getting any errors? Quote Link to comment https://forums.phpfreaks.com/topic/261998-email-is-not-sent/#findComment-1342723 Share on other sites More sharing options...
runnerjp Posted May 3, 2012 Share Posted May 3, 2012 sorry i copied the wrong part... died('We are sorry, but there appears to be a problem with the form you submitted.'); that should be die('We are sorry, but there appears to be a problem with the form you submitted.'); Quote Link to comment https://forums.phpfreaks.com/topic/261998-email-is-not-sent/#findComment-1342734 Share on other sites More sharing options...
Jessica Posted May 4, 2012 Share Posted May 4, 2012 sorry i copied the wrong part... died('We are sorry, but there appears to be a problem with the form you submitted.'); that should be die('We are sorry, but there appears to be a problem with the form you submitted.'); Still wrong. He's defined died as a function. He can call it fred for all he wants, it's his function. Quote Link to comment https://forums.phpfreaks.com/topic/261998-email-is-not-sent/#findComment-1342985 Share on other sites More sharing options...
scootstah Posted May 4, 2012 Share Posted May 4, 2012 Sorry, but "it's not working" is not going to get you any answers. WHAT isn't working? Is the email not sending at all? Is the email sending but with incorrect/unexpected data? Is there a PHP error? We aren't looking at your monitor, we don't know what "isn't working" means. Also, remove the @ symbol from the mail function to see if it is producing errors. Quote Link to comment https://forums.phpfreaks.com/topic/261998-email-is-not-sent/#findComment-1342986 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.