Здравейте колеги искам да направа, на моята контактна форма да има Exclude lines with blank mail-tags from output как става това ето го и самия код, който ползвам.
PHP:
<?php
if($_POST)
{
//check if its an ajax request, exit if not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
die();
}
$to_Email = "mail"; //Replace with recipient email address
$subject = 'subject'; //Subject line for emails
//check $_POST vars are set, exit if any 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 is less than 4 it will throw an HTTP error.
{
header('HTTP/1.1 500 Изпратено успешно!');
exit();
}
if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
{
header('HTTP/1.1 500 Моля въведете валиден имейл адрес');
exit();
}
if(!is_numeric($user_Phone)) //check entered data is numbers
{
header('HTTP/1.1 500 моля попълнете коре');
exit();
}
if(strlen($user_Message)<5) //check emtpy message
{
header('HTTP/1.1 500 Моля попълнете коректно полето');
exit();
}
//proceed with PHP email.
$headers = "From: $user_Email \n"
."Reply-To: $user_Email \n"
."Content-type: text/plain; charset=utf-8; \n"
."X-Mailer: PHP/".phpversion();
$send = "заглавие";
$headers1 = "From: $send <$to_Email> \n"
."Content-type: text/plain; charset=utf-8; \n"
."X-Mailer: PHP/".phpversion();
$info = текст ";
@$sentMail = mail($to_Email, $subject, $info ,$headers);
$auto_sub = "текст";
@$sentMail = mail($user_Email,"Съпорт", $auto_sub, $headers1);
if(!$sentMail)
{
header('HTTP/1.1 500 Could not send mail! Sorry..');
exit();
}else{
echo 'Изпратено е успещно. <br/>';
}
}
?>