jalen Posted June 1, 2009 Share Posted June 1, 2009 I have a form that user's fill out and when click submit supposedly it would send me all his message to my email. but there seems to be a problem and is not working as it should. anyone have any clues as to why, please let me know. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/ Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 The problem is on line 37. Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846509 Share on other sites More sharing options...
jalen Posted June 1, 2009 Author Share Posted June 1, 2009 what do you mean problem is on line 37? Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846511 Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 pretty self-explanatory... there's a problem, and it's on the 37th line of your code. Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846512 Share on other sites More sharing options...
jalen Posted June 1, 2009 Author Share Posted June 1, 2009 It doesn't show any error message it will display sent thank you etc. but when I go to my mail I don't see it sent. and you didn't see my code how you know is line 37? Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846516 Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 obviously because I'm psychic. Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846519 Share on other sites More sharing options...
jalen Posted June 1, 2009 Author Share Posted June 1, 2009 but there is no error, it says thank you your message is sent. Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846525 Share on other sites More sharing options...
MadTechie Posted June 1, 2009 Share Posted June 1, 2009 obviously because I'm psychic. Yes, we know that CV, but for anyone else they would need to see the code to have a clue.. shame we're not all psychic ~Sighs~. Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846527 Share on other sites More sharing options...
jalen Posted June 1, 2009 Author Share Posted June 1, 2009 Im not sure if it has anything to do with the php mail function in the ini file? Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846531 Share on other sites More sharing options...
MadTechie Posted June 1, 2009 Share Posted June 1, 2009 CV, can you help us here, of course not being psychic myself, i have no useful information to work with Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846535 Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 Please deposit 25 cents. Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846540 Share on other sites More sharing options...
elis Posted June 1, 2009 Share Posted June 1, 2009 Jalen, Please post your code. Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846550 Share on other sites More sharing options...
jalen Posted June 1, 2009 Author Share Posted June 1, 2009 here is the code thx <form action="FormToEmail.php" method="post"> <table border="1" bgcolor="yellow" cellspacing="5"> <tr><td>Email address</td><td><input type="text" size="30" name="my_email"></td></tr> <tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr> <tr><td>Email address</td><td><input type="text" size="30" name="email"></td></tr> <tr><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr> <tr><td> </td><td><input type="submit" value="Send"></td></tr> </table> </form> <?php $my_email = "myemail"; $errors = array(); if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}} function recursive_array_check_header($element_value) { global $set; if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}} else { foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);} } } recursive_array_check_header($_REQUEST); if($set){$errors[] = "You cannot send an email header";} unset($set); if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) { if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";} $_REQUEST['email'] = trim($_REQUEST['email']); if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}} } if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";} function recursive_array_check_blank($element_value) { global $set; if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}} else { foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);} } } recursive_array_check_blank($_REQUEST); if(!$set){$errors[] = "You cannot send a blank form";} unset($set); if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;} if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");} function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");} $message = build_message($_REQUEST); $message = stripslashes($message); $subject = "FormToEmail Comments"; $headers = "From: " . $_REQUEST['email']; mail($my_email,$subject,$message,$headers); ?> <html> <head> </head> <body bgcolor="yellow" text="#000000"> <div> <center> <b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b> <br>Your message has been sent </center> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846557 Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 13 posts before code was posted. That must be some kind of world record. Stupid question: $my_email = "myemail"; you just changed it to "myemail" for the purposes of posting here, and that is not what you really have in your code, right? Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846560 Share on other sites More sharing options...
MadTechie Posted June 1, 2009 Share Posted June 1, 2009 Also your code will always say sent as you don't check if mail was sucessful change mail($my_email, $subject, $message, $headers) to if(!mail($my_email, $subject, $message, $headers)) { trigger_error("Email Failed!", E_USER_WARNING); //die("ERROR SENDING"); } Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846561 Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 well I c/p'd your code and changed that line to my email address and it sent it just fine. So... p.s.- judging by the context of your email body I suspect what you are wanting to do is this: $my_email = $_POST['my_email']; Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846562 Share on other sites More sharing options...
MadTechie Posted June 1, 2009 Share Posted June 1, 2009 So.. try a simple test if(mail('abc@xyz.com', 'My Subject', "Hello")) { echo "sent"; }else{ echo "failed"; } if that fails check your PHP.INI setup SMTP, if your account require authentication then try phpmailer() Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846566 Share on other sites More sharing options...
jalen Posted June 1, 2009 Author Share Posted June 1, 2009 you just changed it to "myemail" for the purposes of posting here, and that is not what you really have in your code, right? yea that was my personal email in replacement. Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846573 Share on other sites More sharing options...
jalen Posted June 1, 2009 Author Share Posted June 1, 2009 Ok, I changed what you guys said, and these are the two things I changed and is giving me an error message. Failed. Do you know why? if(mail('myemailhere', 'My Subject', "Hello")) { echo "sent"; }else{ echo "failed"; } $my_email = $_POST['my_emai herel']; Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846576 Share on other sites More sharing options...
jalen Posted June 1, 2009 Author Share Posted June 1, 2009 how do you check your php ini and SMTP to fix this? thx Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846580 Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 $my_email = $_POST['my_emai herel']; your form has an input field with the name of "my_email" and the form method is "post" so when I put $my_email = $_POST['my_email']; That's exactly how it should appear. I assumed that that's how it should be, seeing as how the variable is coincidentally named the same as the form input field name, and you don't seem to be making use of that field anywhere else in your script... But you are saying you had your physical email there, so I'm going to *assume* that that wasn't the problem to begin with.... right? Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846581 Share on other sites More sharing options...
MadTechie Posted June 1, 2009 Share Posted June 1, 2009 Open your PHP.ini file and check the following [mail function] SMTP = localhost smtp_port = 25 SMTP should be the mail server and the smtp_port should be its port! if your account require authentication then try phpmailer() Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846582 Share on other sites More sharing options...
PFMaBiSmAd Posted June 1, 2009 Share Posted June 1, 2009 To find out why the mail() function call failed (so that you can address the actual problem, rather than guessing), add the following two lines of code (for debugging purposes only, remove them later) immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846584 Share on other sites More sharing options...
jalen Posted June 1, 2009 Author Share Posted June 1, 2009 That's exactly how it should appear. I assumed that that's how it should be, seeing as how the variable is coincidentally named the same as the form input field name, and you don't seem to be making use of that field anywhere else in your script... But you are saying you had your physical email there, so I'm going to *assume* that that wasn't the problem to begin with.... right? yea! Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846587 Share on other sites More sharing options...
jalen Posted June 1, 2009 Author Share Posted June 1, 2009 Open your PHP.ini file and check the following Code: [select] [mail function] SMTP = localhost smtp_port = 25 SMTP should be the mail server and the smtp_port should be its port! this is what I have in my php ini for these: [mail function] ; For Win32 only. SMTP = localhost smtp_port = 25 To find out why the mail() function call failed (so that you can address the actual problem, rather than guessing), add the following two lines of code (for debugging purposes only, remove them later) immediately after your first opening <?php tag - Code: [select] ini_set("display_errors", "1"); error_reporting(E_ALL); this is what I have after putting this code at beginning of <?php Notice: Undefined index: myemail in C:\Apache\htdocs\FormToEmail.php on line 82 Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Apache\htdocs\FormToEmail.php on line 196 failed Quote Link to comment https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846591 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.