aneeb Posted March 23, 2013 Share Posted March 23, 2013 Hey Everyone! i have write this code for sending mail but it is not working. It is echoing the Error message. <?phpinclude "config.php";if(!$_POST) exit;$email = $_POST['email'];if(!preg_match('/\.([^\.]*$)/',$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 = "aneeb@gmail.com";$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!';}}?> Please help me.. Link to comment Share on other sites More sharing options...
jeffman Posted March 23, 2013 Share Posted March 23, 2013 (edited) 0. Turn on error reporting and temporarily remove the @ symbol from your call to mail() so you can get some error information. 1. Try sending a message with very simple values to make sure mail() even works on your system. 2. Try commenting-out (going around) your foreach structure to see if something in there is weird. 3. Try echoing the values that you are passing to mail() to see if they make sense. Edited March 23, 2013 by Deirdre's Dad Link to comment Share on other sites More sharing options...
Ingolme Posted March 24, 2013 Share Posted March 24, 2013 If you're running this locally, it probably won't work unless you've installed an SMTP server and configured PHP to use it. Link to comment Share on other sites More sharing options...
aneeb Posted March 24, 2013 Author Share Posted March 24, 2013 thanks for replying.... Sir you are saying that it won't work on local, so if i upload it on server would it work???? Please reply.. Link to comment Share on other sites More sharing options...
Ingolme Posted March 24, 2013 Share Posted March 24, 2013 It will if the server is configured properly. It would also work locally if you set up the local server to send e-mails with an SMTP server. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now