kpontau Posted March 2, 2014 Share Posted March 2, 2014 I'm new to php coding. I got this script from a free template, but it doesn't work when I try sending an email. html part <form action="contact.php" method="post" id="cform" name="cform"> <ul id="homehireus" class="hireform contactform"> <li> <label>Name:<span class="required">*</span></label> <input name="name" id="name" type="text" value="" tabindex="1"> </li> <li> <label>Phone:</label> <input name="phone" id="phone" type="text" value="" tabindex="3"> </li> <li> <label>Email:<span class="required">*</span></label> <input name="email" id="email" type="text" value="" tabindex="2"> </li> <li> <label>Subject:<span class="required"></span></label> <input name="subject" id="subject" type="text" value="" tabindex="4"> </li> <li> <input type="button" id="send-message" value="Send Details" tabindex="6"> <div id="output" class="contactpage-msg"></div> </li> <li> <label>Message:<span class="required"></span></label> <textarea name="message" id="message" tabindex="5"></textarea> </li> </ul> </form> </article> </div> </div> </section> </div></div> php part <?php// EDIT THE FOLLOWING LINE BELOW AS REQUIRED$send_email_to = "info@kpontau.com";function send_email($name,$email,$phone,$subject,$message){ global $send_email_to; if($message=='message')$message=''; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= "From: ".$email. "\r\n"; $message = "<strong>Email = </strong>".$email."<br>"; $message .= "<strong>Name = </strong>".$name."<br>"; $message .= "<strong>Phone = </strong>".$phone."<br>"; $message .= "<strong>Message = </strong>".$message."<br>"; @mail($send_email_to, $subject, $message,$headers); return true;}function validate($name,$email,$phone,$message,$subject){ $return_array = array(); $return_array['success'] = '1'; $return_array['name_msg'] = ''; $return_array['email_msg'] = ''; $return_array['phone_msg'] = ''; $return_array['message_msg'] = ''; $return_array['subject_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($phone == '') { $return_array['success'] = '0'; $return_array['phone_msg'] = 'Phone is required'; } else { $string_exp = "/^[A-Za-z .'-]+$/"; if (!preg_match($string_exp, $phone)) { $return_array['success'] = '0'; $return_array['phone_msg'] = 'Enter valid Phone.'; } } if($subject == '') { $return_array['success'] = '0'; $return_array['subject_msg'] = 'Subject is required'; } 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'];$phone = $_POST['phone'];$email = $_POST['email'];$message = $_POST['message'];$subject = $_POST['subject'];$return_array = validate($name,$email,$phone,$message,$subject);if($return_array['success'] == '1'){ send_email($fname,$email,$phone,$subject,$message);}header('Content-type: text/json');echo json_encode($return_array);die();?> What am I doing wrong? Thanks! Link to comment https://forums.phpfreaks.com/topic/286662-mail-code-not-working/ Share on other sites More sharing options...
.josh Posted March 3, 2014 Share Posted March 3, 2014 We aren't here to fix some random 3rd party script you found and don't know anything about. We're here to help people learn and fix code that they try to make. You've got 2 choices, as far as this forum is concerned: 1) make an effort to understand and debug the code, and feel free to ask any specific questions about something you get stuck on, or 2) hire a freelancer to fix it for you. Link to comment https://forums.phpfreaks.com/topic/286662-mail-code-not-working/#findComment-1471282 Share on other sites More sharing options...
Recommended Posts