Jump to content

PHP code for sending mail


aneeb

Recommended Posts

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

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 by Deirdre's Dad
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...