softmind82 Posted May 11, 2017 Share Posted May 11, 2017 I know nothing about PHP but using the following code after editing my web template but my email is not been sending from the form. Please guide me where i am wrong. Thanks <?php //====================================================================== // Variables //====================================================================== //E-mail address. Enter your email define("__TO__", "info@group100.co.uk"); thats the email i want to sent all email //Success message define('__SUCCESS_MESSAGE__', "Your message has been sent. We will reply soon. Thank you!"); //Error message define('__ERROR_MESSAGE__', "Your message hasn't been sent. Please try again."); //Messege when one or more fields are empty define('__MESSAGE_EMPTY_FIELDS__', "Please fill out all fields"); //====================================================================== // Do not change //====================================================================== //E-mail validation function check_email($email){ if(!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ return false; } else { return true; } } //Send mail function send_mail($to,$subject,$message,$headers){ if(@mail($to,$subject,$message,$headers)){ echo json_encode(array('info' => 'success', 'msg' => __SUCCESS_MESSAGE__)); } else { echo json_encode(array('info' => 'error', 'msg' => __ERROR_MESSAGE__)); } } //Get data form and send mail if(isset($_POST['name']) and isset($_POST['mail']) and isset($_POST['messageForm'])){ $name = $_POST['name']; $mail = $_POST['mail']; $subjectForm = $_POST['subjectForm']; $messageForm = $_POST['messageForm']; if($name == '') { echo json_encode(array('info' => 'error', 'msg' => "Please enter your name.")); exit(); } else if($mail == '' or check_email($mail) == false){ echo json_encode(array('info' => 'error', 'msg' => "Please enter valid e-mail.")); exit(); } else if($messageForm == ''){ echo json_encode(array('info' => 'error', 'msg' => "Please enter your message.")); exit(); } else { $to = __TO__; $subject = $subjectForm . ' ' . $name; $message = ' <html> <head> <title>Mail from '. $name .'</title> </head> <body> <table style="width: 500px; font-family: arial; font-size: 14px;" border="1"> <tr style="height: 32px;"> <th align="right" style="width:150px; padding-right:5px;">Name:</th> <td align="left" style="padding-left:5px; line-height: 20px;">'. $name .'</td> </tr> <tr style="height: 32px;"> <th align="right" style="width:150px; padding-right:5px;">E-mail:</th> <td align="left" style="padding-left:5px; line-height: 20px;">'. $mail .'</td> </tr> <tr style="height: 32px;"> <th align="right" style="width:150px; padding-right:5px;">Subject:</th> <td align="left" style="padding-left:5px; line-height: 20px;">'. $subjectForm .'</td> </tr> <tr style="height: 32px;"> <th align="right" style="width:150px; padding-right:5px;">Message:</th> <td align="left" style="padding-left:5px; line-height: 20px;">'. $messageForm .'</td> </tr> </table> </body> </html> '; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= 'From: ' . $mail . "\r\n"; send_mail($to,$subject,$message,$headers); } } else { echo json_encode(array('info' => 'error', 'msg' => __MESSAGE_EMPTY_FIELDS__)); } ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 11, 2017 Share Posted May 11, 2017 How do you know that your script has no errors in it? Turn on php error checking and add some echo (without the json_encode!!!) statements at verious points to see how far your script is running. Did you think this was going to be easy? See my signature. Quote Link to comment 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.