to = $to; return $this; } public function setFrom($name, $addr) { $this->fromName = $name; $this->fromAddr = $addr; return $this; } public function setReturnPath($returnPath) { $this->returnPath = $returnPath; return $this; } public function setBcc($bcc) { $this->bcc = $bcc; return $this; } public function setSubject($subject) { $this->subject = $subject; return $this; } public function setTextBody($textBody) { $this->textBody = $textBody; return $this; } protected function assembleHeaders() { $headers = array(); $headers[] = "From: ".$this->fromName." <".$this->fromAddr.">"; if ($this->bcc) { $headers[] = "Bcc: ".$this->bcc; } return $headers; } public function send() { if ($this->returnPath) { add_filter('phpmailer_init', array($this, 'injectSender'), 10, 2); } $x = wp_mail($this->to, $this->subject, $this->textBody, $this->assembleHeaders()); if ($this->returnPath) { remove_filter('phpmailer_init', array($this, 'injectSender'), 10); } return $this; } public function injectSender($phpmailer) { $phpmailer->Sender = $this->returnPath; } public function clear() { $this->to = null; $this->fromName = null; $this->fromAddr = null; $this->bcc = null; $this->subject = null; $this->textBody = null; return $this; } }