html - PHP Mail form not sending emails on Linux server -
this code , form... acts email sent, never arrives.
i know possibly wrong... anyone?
the website hosted on linux server, , don't know if server blocking emails because of kind of incompatibility... don't know be.
<?php if($_post) { //check if ajax request, exit if not if(!isset($_server['http_x_requested_with']) , strtolower($_server['http_x_requested_with']) != 'xmlhttprequest') { die(); } $to_email = "myemail@gmail.com"; //replace recipient email address $subject = 'ah!! email out there...'; //subject line emails //check $_post vars set, exit if missing if(!isset($_post["username"]) || !isset($_post["useremail"]) || !isset($_post["userphone"]) || !isset($_post["usermessage"])) { die(); } //sanitize input data using php filter_var(). $user_name = filter_var($_post["username"], filter_sanitize_string); $user_email = filter_var($_post["useremail"], filter_sanitize_email); $user_phone = filter_var($_post["userphone"], filter_sanitize_string); $user_message = filter_var($_post["usermessage"], filter_sanitize_string); //additional php validation if(strlen($user_name)<4) // if length less 4 throw http error. { header('http/1.1 500 name short or empty!'); exit(); } if(!filter_var($user_email, filter_validate_email)) //email validation { header('http/1.1 500 please enter valid email!'); exit(); } if(!is_numeric($user_phone)) //check entered data numbers { header('http/1.1 500 numbers allowed in phone field'); exit(); } if(strlen($user_message)<5) //check emtpy message { header('http/1.1 500 short message! please enter something.'); exit(); } //proceed php email. $headers = 'from: '.$user_email.'' . "rn" . 'reply-to: '.$user_email.'' . "rn" . 'x-mailer: php/' . phpversion(); @$sentmail = mail($to_email, $subject, $user_message .' -'.$user_name, $headers); if(!$sentmail) { header('http/1.1 500 couldnot send mail! sorry..'); exit(); }else{ echo 'hi '.$user_name .', thank email! '; echo 'your email has arrived in inbox, need check it.'; } } ?>
here's form:
<fieldset id="contact_form"> <legend>my contact form</legend> <div id="result"></div> <input type="text" name="name" id="inputt" placeholder="enter name" /> <input type="text" name="email" id="inputt" placeholder="enter email" /> <input type="text" name="phone" id="inputt" placeholder="phone number" /> <textarea name="message" id="message" placeholder="enter name"></textarea> <button class="submit_btn" id="submit_btn">submit</button> </fieldset>
your $headers
wrong, you're appending "rn"
instead of "\r\n"
. try instead:
$headers = 'from: '.$user_email. "\r\n" . 'reply-to: '.$user_email. "\r\n" . 'x-mailer: php/' . phpversion();
Comments
Post a Comment