/** * Create a new TBGMimemail and return it * * @param string $subject * @param string $message_plain * @param string $message_html * @param array $recipients * @param string $charset * * @return TBGMimemail */ public function createNewTBGMimemailFromMessage($subject, $message_plain, $message_html = null, $recipients = array(), $charset = 'utf-8') { try { $mail = TBGMimemail::createNewFromMessage($subject, $message_plain, $message_html, $recipients, $charset); $this->_setInitialMailValues($mail); return $mail; } catch (Exception $e) { throw $e; } }
protected function _mail2(TBGMimemail $email) { if (TBGContext::isCLI()) { $server = php_uname('n'); } else { $server = $_SERVER['SERVER_NAME']; } /* Open a socket connection to the mail server SMTP port (25) and read the welcome message. */ $fp = fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); if (!$fp) { if ($this->debug) { echo "No server? {$errno} {$errstr}<br>"; } throw new Exception(TBGContext::getI18n()->__('Could not open connection to server %server on port %port', array('%server' => $this->server, '%port' => $this->port))); } $this->_read_buffer($fp, 'open'); /* Standard "ehlo" message. */ if ($this->ehlo) { fputs($fp, "ehlo {$server}\r\n"); $this->_read_buffer($fp, 'ehlo'); } else { fputs($fp, "helo {$server}\r\n"); $this->_read_buffer($fp, 'helo'); } /* Auth login: (Note that Username and password must be Base64 encoded string.) */ if ($this->username != '') { fputs($fp, "AUTH LOGIN\r\n"); $rv = fgets($fp, 4096); if ($this->debug) { echo base64_decode(mb_substr($rv, 4)) . $this->username . ' ' . $rv . '<br>'; } fputs($fp, base64_encode($this->username) . "\r\n"); $rv = fgets($fp, 4096); if ($this->debug) { echo base64_decode(mb_substr($rv, 4)) . $this->password . ' ' . $rv . '<br>'; } fputs($fp, base64_encode($this->password) . "\r\n"); $rv = $this->_read_buffer($fp, 'user/pass'); if (preg_match("/^500/i", $rv)) { if ($this->debug) { echo 'Not ready to authenticate. (' . $rv . ') Try changing server type'; } throw new Exception(TBGContext::getI18n()->__('Not ready to authenticate. (%rv) Try changing server type', array('%rv' => $rv))); } if (!preg_match("/^235/i", $rv)) { /* OK Authenticated */ if ($this->debug) { echo 'Username / password not accepted on server<br>'; } fclose($fp); throw new Exception(TBGContext::getI18n()->__('Username / password not accepted on server: %rv', array('%rv' => $rv))); } } // "mail from" message and read the return. Assume everything is OK. fputs($fp, "mail from: <{$email->getFromaddress()}>\r\n"); $rv = $this->_read_buffer($fp, 'mail_from'); // "rcpt to" message and read the return. Each name in the $to, $cc, and $bcc array requires one "rcpt to" foreach ($email->getRecipients() as $recipient) { fputs($fp, "rcpt to: <{$recipient['address']}>\r\n"); $rv = $this->_read_buffer($fp, 'to'); } if (preg_match("/^550/i", $rv)) { if ($this->debug) { echo "You are not allowed to send emails through this server."; } throw new Exception(TBGContext::getI18n()->__("You are not allowed to send emails through this server. \nThe error was: %rv", array('%rv' => $rv))); } foreach ($email->getCC() as $cc) { fputs($fp, "rcpt to: <{$cc['address']}>\r\n"); $this->_read_buffer($fp, 'cc'); } foreach ($email->getBCC() as $bcc) { fputs($fp, "rcpt to: <{$bcc['address']}>\r\n"); $this->_read_buffer($fp, 'bcc'); } /* "data" message and the message body follows. */ fputs($fp, "data\r\n"); $this->_read_buffer($fp, 'data'); /* Standard message parts. */ fputs($fp, $email->getHeadersAsString()); foreach ($email->getBody(true) as $body_line) { fputs($fp, $body_line); } /* "quit" message and done. */ fputs($fp, ".\r\n"); fputs($fp, "quit\r\n"); $rv = $this->_read_buffer($fp, 'quit'); fclose($fp); /* status 250 if Message accepted for delivery */ if (preg_match("/^250/i", $rv)) { return true; } else { if ($this->debug) { echo "Did not receive a confirmation message from the mail server."; } throw new Exception(TBGContext::getI18n()->__("Did not receive a confirmation message from the mail server.. \nHowever, we received: %rv", array('%rv' => $rv))); } }
protected function _setAdditionalMailValues(TBGMimemail $mail, array $parameters) { $mail->addReplacementValues(array('%link_to_reset_password' => isset($parameters['user']) ? $this->getMailingUrl() . TBGContext::getRouting()->generate('reset_password', array('user' => str_replace('.', '%2E', $parameters['user']->getUsername()), 'reset_hash' => $parameters['user']->getActivationKey())) : '')); $mail->addReplacementValues(array('%link_to_activate' => isset($parameters['user']) ? $this->getMailingUrl() . TBGContext::getRouting()->generate('activate', array('user' => str_replace('.', '%2E', $parameters['user']->getUsername()), 'key' => $parameters['user']->getActivationKey())) : '')); }