Jump to content

PHP code for sending mail


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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...