nzGoner Posted September 27, 2010 Share Posted September 27, 2010 well... some part works! when i check my email, it says "nobody" instead of the senders email and it is not showing the right subject and the company field wont show up here is my html code thanks ~ Code <form action="contact.php" method="POST" id="contactform"> <ol> <li> <label for="name">First Name <span class="red">*</span></label> <input id="name" name="name" class="text" /> </li> <li> <label for="email">Your email <span class="red">*</span></label> <input id="email" name="email" class="text" /> </li> <li> <label for="company">Company</label> <input id="company" name="company" class="text" /> </li> <li> <label for="subject">Subject</label> <input id="subject" name="subject" class="text" /> </li> <li> <label for="message">Message <span class="red">*</span></label> <textarea id="message" name="message" rows="6" cols="50"></textarea> </li> <li class="buttons"> <input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" /> <div class="clr"></div> </li> </ol> </form> here is my php Code <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','message'); $required = array('name','email','message'); $your_email = "[email protected]"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?> Link to comment https://forums.phpfreaks.com/topic/214511-contact-form-no-sender/ Share on other sites More sharing options...
nzGoner Posted September 27, 2010 Author Share Posted September 27, 2010 anyone D: Link to comment https://forums.phpfreaks.com/topic/214511-contact-form-no-sender/#findComment-1116424 Share on other sites More sharing options...
rwwd Posted September 27, 2010 Share Posted September 27, 2010 Well, the first thing that strikes me is that there is no submit button, and you need a submit button to send a form! And on the receiver script there is no error handler for the $_POST array for if it isset() but not having the value you expect, also the ereg function has been officially superseded by preg, I forget which version of PHP, but it's something that is best fixed now. And seriously, the @ prefixing the mail() is a bad Idea, it only returns a boolean so personally I would leave it so that you get AS MUCH information back from the function as possible, the mail() isn't very helpful anyway as it doesn't really give any confirmation on the successful sending of an email until it actually arrives in the inbox (I would check the junk folder too, the get in there sometimes...) Lastly, you need to run the strip_tags() function over the entire $_POST array so that potentially malicious code can be stripped from the user submitted data - NEVER trust a user! Hopefully some of that makes sense. Rw Link to comment https://forums.phpfreaks.com/topic/214511-contact-form-no-sender/#findComment-1116437 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.