summaryrefslogtreecommitdiff
path: root/htdocs/src/Email.inc.php
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-05-24 15:01:09 -0700
committerJesse Morgan <jesse@jesterpm.net ; true>2011-05-24 15:01:09 -0700
commitd69c19b7a138659962d3c20c2487f4f13da997c5 (patch)
tree2300eaa3ed16fd31b8e844df72bb49434298a2e8 /htdocs/src/Email.inc.php
parenta1bbd6bfb8dd3812c70acdeff793cd9d78bdc219 (diff)
Working on email validation
Diffstat (limited to 'htdocs/src/Email.inc.php')
-rw-r--r--htdocs/src/Email.inc.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/htdocs/src/Email.inc.php b/htdocs/src/Email.inc.php
new file mode 100644
index 0000000..b828780
--- /dev/null
+++ b/htdocs/src/Email.inc.php
@@ -0,0 +1,72 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+class Email {
+ private $subject;
+ private $to;
+ private $from;
+ private $fromname;
+ private $message;
+ private $headers;
+
+ public function __construct($to) {
+ $this->to = $to;
+ $this->from = $GLOBALS['CONFIG']['email_from'];
+ $this->message = "";
+ $this->headers = array();
+ }
+
+ public function setFrom($from) {
+ $this->from = $from;
+
+ if (strstr($from, "<"))
+ $this->fromname = preg_replace("/([^<>]+) <([^<>]+)>/", "$1", $from);
+ }
+
+ public function setSubject($subject) {
+ $this->subject = $subject;
+ }
+
+ public function addHeader($header, $value) {
+ $this->headers[] = "$header: $value";
+ }
+
+ public function appendMessage($message) {
+ $this->message .= $message;
+ }
+
+ public function send($logprefix="") {
+ // Headers
+ if ($this->fromname) {
+ $headers = "From: ". $this->fromname ." <". $this->from .">\n";
+ } else {
+ $headers = "From: ". $this->from ."\n";
+ }
+ $headers .= "Reply-To: ". $this->from ."\n";
+ $headers .= "Date: ". date("r") ."\n";
+ $headers .= join("\n", $this->headers);
+
+ if ($GLOBALS['CONFIG']['production']) {
+ $ret = mail($this->to, $this->subject, $this->message, $headers);
+
+ } else {
+ // If we're not in production, save to file instead of emailing.
+ $fh = fopen($GLOBALS['CONFIG']['root'].'/emails.log', 'a');
+ fwrite($fh, sprintf("To: %s\n%s\nSubject: %s\n\n%s\n\n",
+ $this->to, $headers, $this->subject, $this->message));
+ fclose($fh);
+ }
+
+ // TODO: Add logger
+ //$GLOBALS['logger']->log_email($ret, $this->to, $this->subject, $logprefix);
+ }
+}
+
+?>