Created
February 13, 2012 03:06
-
-
Save possan/1813048 to your computer and use it in GitHub Desktop.
Simple post data mailer - sends all posted fields and uploaded files by email.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// | |
// Simple post data mailer - sends all posted fields and uploaded files by email. | |
// | |
// USAGE: | |
// curl -F field1=value1 -F field2=value2 -F file1=@/tmp/test.txt http://example.com/script.php | |
// | |
// TODO: check for spam post | |
$to = "[email protected]"; | |
$from = "[email protected]"; | |
$subject = "New item posted: ".$_POST["name"]; | |
require_once('Mail.php'); | |
require_once('Mail/mime.php'); | |
$message = new Mail_mime(); | |
$body = ""; | |
foreach($_POST as $k => $v) | |
$body .= $k.":\n\t".$v."\n\n"; | |
foreach ($_FILES as $file) | |
if ($file['tmp_name'] > '') | |
$message->addAttachment( $file['tmp_name'], $file['type'], $file['name'] ); | |
$message->setTXTBody($body); | |
$body = $message->get(); | |
$extraheaders = array("From"=>$from, "Subject"=>$subject); | |
$headers = $message->headers($extraheaders); | |
$mail = Mail::factory("mail"); | |
$mail->send($to, $headers, $body); | |
echo "OK\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment