Example #1
0
 /**
  * Send the given Message.
  *
  * Recipient/sender data will be retrieved from the Message API.
  * The return value is the number of recipients who were accepted for delivery.
  *
  * @param MessageInterface $message
  *
  * @return int
  */
 public function send(MessageInterface $message)
 {
     $smtp_conn = fsockopen($this->host, $this->port, $errno, $errstr, 10);
     $log = $this->get_data($smtp_conn);
     fputs($smtp_conn, "EHLO " . $this->username . "\r\n");
     $log = $this->get_data($smtp_conn);
     fputs($smtp_conn, "AUTH LOGIN\r\n");
     $log = $this->get_data($smtp_conn);
     fputs($smtp_conn, base64_encode($this->username) . "\r\n");
     $log = $this->get_data($smtp_conn);
     fputs($smtp_conn, base64_encode($this->password) . "\r\n");
     $log = $this->get_data($smtp_conn);
     $size_msg = strlen($message->toString());
     fputs($smtp_conn, "MAIL FROM:<" . $this->username . "> SIZE=" . $size_msg . "\r\n");
     $log = $this->get_data($smtp_conn);
     foreach ($message->getTo() as $userMail => $userName) {
         fputs($smtp_conn, "RCPT TO: <" . $userMail . ">" . "\r\n");
         $log = $this->get_data($smtp_conn);
     }
     fputs($smtp_conn, "DATA" . "\r\n");
     $log = $this->get_data($smtp_conn);
     fputs($smtp_conn, $message->toString() . "\r\n.\r\n");
     $log = $this->get_data($smtp_conn);
     fputs($smtp_conn, "QUIT\r\n");
     $log = $this->get_data($smtp_conn);
     return count($message->getTo());
 }
Example #2
0
 /**
  * Send the given Message.
  *
  * Recipient/sender data will be retrieved from the Message API.
  * The return value is the number of recipients who were accepted for delivery.
  *
  * @param MessageInterface $message
  *
  * @return int
  */
 public function send(MessageInterface $message)
 {
     if (!array_key_exists('host', $this->configuration) || !array_key_exists('port', $this->configuration) || !array_key_exists('username', $this->configuration) || !array_key_exists('password', $this->configuration)) {
         return 0;
     }
     $messageStr = $message->toString();
     $toStr = $this->getTo($messageStr, true);
     $to = $this->getTo($messageStr);
     $from = $this->getFrom($messageStr);
     $subject = $message->getSubject();
     $endHeaders = strpos($messageStr, MessageInterface::LINE_SEPARATOR . MessageInterface::LINE_SEPARATOR);
     $headers = substr($messageStr, 0, $endHeaders);
     $body = substr($messageStr, $endHeaders + 4);
     foreach ($from as $address => $name) {
         $from_email = $address;
         $from_name = $name;
     }
     $smtp_host = $this->configuration['host'];
     $smtp_port = $this->configuration['port'];
     $user = $this->configuration['username'];
     $pass = $this->configuration['password'];
     $from_email = isset($from_email) && !empty($from_email) ? $from_email : $user;
     if (!($socket = fsockopen($smtp_host, $smtp_port, $errno, $errstr, 15))) {
         return 0;
     }
     $this->serverParse($socket, '220');
     fwrite($socket, 'EHLO smtp.gmail.com' . Message::LINE_SEPARATOR);
     $this->serverParse($socket, '250', __LINE__);
     fwrite($socket, 'AUTH LOGIN' . Message::LINE_SEPARATOR);
     $this->serverParse($socket, '334', __LINE__);
     fwrite($socket, base64_encode($user) . Message::LINE_SEPARATOR);
     $this->serverParse($socket, '334', __LINE__);
     fwrite($socket, base64_encode($pass) . Message::LINE_SEPARATOR);
     $this->serverParse($socket, '235', __LINE__);
     fwrite($socket, 'MAIL FROM: <' . $from_email . '>' . Message::LINE_SEPARATOR);
     $this->serverParse($socket, '250', __LINE__);
     foreach ($to as $email => $name) {
         fwrite($socket, 'RCPT TO: <' . $email . '>' . Message::LINE_SEPARATOR);
         $this->serverParse($socket, '250', __LINE__);
     }
     fwrite($socket, 'DATA' . Message::LINE_SEPARATOR);
     $this->serverParse($socket, '354', __LINE__);
     fwrite($socket, 'Subject: ' . $subject . Message::LINE_SEPARATOR . 'To: ' . $toStr . Message::LINE_SEPARATOR . $headers . Message::LINE_SEPARATOR . Message::LINE_SEPARATOR . $body . Message::LINE_SEPARATOR);
     fwrite($socket, '.' . Message::LINE_SEPARATOR);
     $this->serverParse($socket, '250', __LINE__);
     fwrite($socket, 'QUIT' . Message::LINE_SEPARATOR);
     fclose($socket);
     return count($to);
 }
Example #3
0
 /**
  * Send the given Message.
  *
  * Recipient/sender data will be retrieved from the Message API.
  * The return value is the number of recipients who were accepted for delivery.
  *
  * @param MessageInterface $message
  * @return int
  */
 public function send(MessageInterface $message)
 {
     $messageStr = $message->toString();
     $toArr = $this->getTo($messageStr);
     $to = implode(', ', array_keys($toArr));
     $subject = $message->getSubject();
     $endHeaders = strpos($messageStr, MessageInterface::LINE_SEPARATOR . MessageInterface::LINE_SEPARATOR);
     $headers = substr($messageStr, 0, $endHeaders);
     $body = substr($messageStr, $endHeaders + 4);
     if (!mail($to, $subject, $body, $headers)) {
         return 0;
     } else {
         return count($message->getTo());
     }
 }
Example #4
0
 /**
  * Send the given Message.
  *
  * Recipient/sender data will be retrieved from the Message API.
  * The return value is the number of recipients who were accepted for delivery.
  *
  * @param MessageInterface $message
  *
  * @return int
  */
 public function send(MessageInterface $message)
 {
     $eol = Message::LINE_SEPARATOR;
     $messageString = $message->toString();
     $startBoundary = strpos($messageString, 'boundary');
     $endBoundary = strpos($messageString, $eol . $eol, $startBoundary);
     $startContent = $endBoundary;
     $content = substr($messageString, $startContent + strlen($eol . $eol));
     $messageString = substr_replace($messageString, '', $startContent) . $eol . $eol;
     $messageString = str_replace($eol . 'boundary', $eol . ' ' . 'boundary', $messageString);
     $content = str_replace($eol . 'boundary', $eol . ' ' . 'boundary', $content);
     if (mail(null, null, $content, $messageString)) {
         return count($message->getTo());
     } else {
         return '0';
     }
 }