Skip to content

Instantly share code, notes, and snippets.

@jda
Created December 19, 2012 20:42
Show Gist options
  • Save jda/4340254 to your computer and use it in GitHub Desktop.
Save jda/4340254 to your computer and use it in GitHub Desktop.
Generic Form Mailer
<?php
// Generic form mailer
// Settings you can change
$to = "[email protected]";
$subject = "Contact form";
$username = "[email protected]";
$password = "email passwd here";
// add form elements below to exclude them from the mail
$exclude = array(
"test1",
"test2",
);
// Don't change stuff below this line
// We take whatever we get and spit it out in a email
require_once "Mail.php";
// set up params for Mail factory
$p = array();
$p["host"] = "mail.netwurx.net";
$p["port"] = 587;
$p["auth"] = true;
$p["username"] = $username;
$p["password"] = $password;
$m =& Mail::factory("smtp", $p);
// Set up headers to go on message
$h = array();
$h['From'] = $to;
$h['To'] = $to;
$h['Subject'] = $subject;
$newurl = $_POST["redirect"];
$body = "";
foreach ($exclude as $key) {
unset($_POST[$key]);
}
foreach ($_POST as $key => $val) {
$body .= "$key: $val\n\n";
}
$res = $m->send($to, $h, $body);
if ($newurl != "") {
header("Location:$newurl");
exit();
} else {
print "Generic Formmail. New URL not set.\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment