ianhaney Posted February 18, 2013 Share Posted February 18, 2013 Hi I have a html contact form in my website and it's action is using a php file and I am trying to get the contact form to send a email to two different email addresses but can't get it working correctly The php file coding the contact form is using is below <?php // EDIT THE 2 LINES BELOW AS REQUIRED $send_email_to = "sales@bhwebsites.co.uk"; $ccemail = "sales@irhwebsites.co.uk"; $email_subject = "Enquiry from the website"; function send_email($name,$email,$email_message) { global $send_email_to; global $ccemail; global $email_subject; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= "From: ".$email. "\r\n"; $headers .= "Cc: ".$ccemail. "\r\n"; $message = "<strong>Email = </strong>".$email."<br>"; $message .= "<strong>Name = </strong>".$name."<br>"; $message .= "<strong>Message = </strong>".$email_message."<br>"; @mail($send_email_to, $ccemail, $email_subject, $message,$headers); return true; } function validate($name,$email,$message) { $return_array = array(); $return_array['success'] = '1'; $return_array['name_msg'] = ''; $return_array['email_msg'] = ''; $return_array['message_msg'] = ''; if($email == '') { $return_array['success'] = '0'; $return_array['email_msg'] = 'email is required'; } else { $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email)) { $return_array['success'] = '0'; $return_array['email_msg'] = 'enter valid email.'; } } if($name == '') { $return_array['success'] = '0'; $return_array['name_msg'] = 'name is required'; } else { $string_exp = "/^[A-Za-z .'-]+$/"; if (!preg_match($string_exp, $name)) { $return_array['success'] = '0'; $return_array['name_msg'] = 'enter valid name.'; } } if($message == '') { $return_array['success'] = '0'; $return_array['message_msg'] = 'message is required'; } else { if (strlen($message) < 2) { $return_array['success'] = '0'; $return_array['message_msg'] = 'enter valid message.'; } } return $return_array; } $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $return_array = validate($name,$email,$message); if($return_array['success'] == '1') { send_email($name,$email,$message); } header('Content-type: text/json'); echo json_encode($return_array); die(); ?> Any help would be great Kind regards Ian Quote Link to comment https://forums.phpfreaks.com/topic/274638-php-email-help/ 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.