Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

PHP Mailer

// This is a single file php mailer that I wrote for someone else. I have removed most of the parts that relate it to the client.
<?php
$valid_ref = "";
$send_name  = "";
$send_email = "";
$subject    = "";

//clean input in case of header injection attempts!
function clean_it($value, $check_all_patterns = true) {
  $patterns[0] = '/content-type:/';
  $patterns[1] = '/to:/';
  $patterns[2] = '/cc:/';
  $patterns[3] = '/bcc:/';
  
  if ($check_all_patterns) {
    $patterns[4] = '/\r/';
    $patterns[5] = '/\n/';
    $patterns[6] = '/%0a/';
    $patterns[7] = '/%0d/';
  }
  return preg_replace($patterns, "", $value);
}

$first_name = clean_it($_POST['first_name']);
$last_name  = clean_it($_POST['last_name']);
$address    = clean_it($_POST['address']);
$city       = clean_it($_POST['city']);
$state      = clean_it($_POST['state']);
$zip        = clean_it($_POST['zip']);
$email      = clean_it($_POST["email"]);
$extra      = clean_it($_POST["extra"]);

$error_msg  = 'Note: Message not sent. Please try again.';

$success_sent_msg = '

 

Your message has been successfully sent. Continue ⇥

'; // email variable not set - load $valid_ref page if (!isset($_POST['email'])) { echo ""; exit; } $ref_page=$_SERVER["HTTP_REFERER"]; $valid_referrer=0; if($ref_page==$valid_ref) $valid_referrer=1; if(!$valid_referrer) { echo ""; exit; } $themessage = <<<EOT $extra Sincerely yours, $first_name $last_name $address $city, $state $zip $email EOT; mail("$send_name <$send_email>", "$subject", "$themessage", "From: $first_name $last_name <$email>\nReply-To: $first_name $last_name <$email>"); echo $success_sent_msg; ?>

PHP Single File Mailer

<?php
$valid_ref = "";
$send_name  = "";
$send_email = "";
$subject    = "";

//clean input in case of header injection attempts!
function clean_it($value, $check_all_patterns = true) {
  $patterns[0] = '/content-type:/';
  $patterns[1] = '/to:/';
  $patterns[2] = '/cc:/';
  $patterns[3] = '/bcc:/';
  
  if ($check_all_patterns) {
    $patterns[4] = '/\r/';
    $patterns[5] = '/\n/';
    $patterns[6] = '/%0a/';
    $patterns[7] = '/%0d/';
  }
  return preg_replace($patterns, "", $value);
}

$first_name = clean_it($_POST['first_name']);
$last_name  = clean_it($_POST['last_name']);
$address    = clean_it($_POST['address']);
$city       = clean_it($_POST['city']);
$state      = clean_it($_POST['state']);
$zip        = clean_it($_POST['zip']);
$email      = clean_it($_POST["email"]);
$extra      = clean_it($_POST["extra"]);

$error_msg  = 'Note: Message not sent. Please try again.';

$success_sent_msg = '

 

Your message has been successfully sent. Continue ⇥

'; // email variable not set - load $valid_ref page if (!isset($_POST['email'])) { echo ""; exit; } $ref_page=$_SERVER["HTTP_REFERER"]; $valid_referrer=0; if($ref_page==$valid_ref) $valid_referrer=1; if(!$valid_referrer) { echo ""; exit; } $themessage = <<<EOT $extra Sincerely yours, $first_name $last_name $address $city, $state $zip $email EOT; mail("$send_name <$send_email>", "$subject", "$themessage", "From: $first_name $last_name <$email>\nReply-To: $first_name $last_name <$email>"); echo $success_sent_msg; ?>
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed