Skip to content

Instantly share code, notes, and snippets.

@bondarolik
Created August 30, 2012 00:14
Show Gist options
  • Save bondarolik/3520832 to your computer and use it in GitHub Desktop.
Save bondarolik/3520832 to your computer and use it in GitHub Desktop.
Simple function to send php form
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$user_name = trim($_POST['name']);
$user_email = trim($_POST['email']);
$user_message = trim($_POST['message']);
$action = trim($_POST['action']);
if (strlen($user_name) == 0) { echo "Error! Представьтесь, пожалуйста."; exit(); }
if (strlen($user_email) == 0) { echo "Error! Введите ваш емайл."; exit(); }
if (strlen($user_message) == 0) { echo "Error! Сообщение не может быть пустым."; exit(); }
switch ($action) {
case 'feedback':
$user_phone = trim($_POST['phone']);
$user_subject = trim($_POST['subject']);
$subject = '[ Feedback Slaff.net ] :: ' . $user_subject;
break;
case 'commentopionion':
$post_link = trim($_POST['post_link']);
$post_name = trim($_POST['post_name']);
$subject = '[ Feedback ] :: "'. $post_name .'"';
break;
}
$to = 'your@email.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '.$user_name .'<'.$user_email.'>' . "\r\n";
$message = '
<html>
<head>
<title>Message from your website</title>
</head>
<body style="font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#333;">
<p><strong>'.$user_name.'</strong> sent you a message:</p>
<p>'.$user_message.'</p>
<p><strong>Phone number/скайп</strong>: '. $user_phone .'</p>
<p><strong>Time</strong>: '. date("F j, Y, g:i a") .'</p>
</body>
</html>';
mail($to, $subject, $message, $headers);
echo "Thank you! I've got your mail.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment