发送电子邮件给多个收件人zend 2

时间:2015-04-05 15:18:50

标签: database model-view-controller zend-framework2 zend-mail

我不想使用zend框架2将相同的邮件发送到从数据库中检索的多个收件人。使用我的解决方案,我只能显示来自数据库的所有电子邮件,但我无法向他们发送邮件。我不知道究竟是什么问题。这是我在indexController中的动作:

    public function eventdetailsAction() { 
$id = (int) $this->params()->fromRoute('id', 0); 
$this->layout()->setVariable('lang', $this->params()->fromRoute('lang',     'en_US')); 
$this->layout()->setVariable('action', $this->params()->fromRoute('action', 'index')); 
$request = $this->getRequest(); 
$aPost = $request->getPost(); 
if (isset($aPost['invitUser'])) { 

    $user = new Container('user'); 
    $db = $this->getServiceLocator()->get('db1'); 

    if (!$user->offsetExists('id')) { 
        $idconnected = '0'; 
    } else { 

        $user = new Container('user'); 
        $db = $this->getServiceLocator()->get('db1'); 

        if (!$user->offsetExists('id')) { 
            $idconnected = '0'; 
        } else { 

            $idconnected = $user->offsetGet('id'); 

            $sql = "SELECT * FROM user"; 
            $statement = $db->query($sql); 
            $res = $statement->execute(); 

            if ($res instanceof ResultInterface && $res->isQueryResult()) { 
                $resultSet = new ResultSet; 
                $resultSet->initialize($res); 

                $message = new Message(); 
                foreach ($resultSet as $row) { 
                    echo $row->email . PHP_EOL; 
                    $message->addTo($row->email) 
                            ->addTo('xxxxx@hotmail.com', 'eee@web.com') 
                            ->addFrom('xxxxx@gmail.com') 
                            ->setSubject('Invitation for the event : Event Latino'); 
                } 

            // Setup SMTP transport using LOGIN authentication 
            $transport = new SmtpTransport(); 
            $options = new SmtpOptions(array( 
                'host' => 'smtp.gmail.com', 
                'connection_class' => 'login', 
                'connection_config' => array( 
                    'ssl' => 'tls', 
                    'username' => 'xxxxx@gmail.com', 
                    'password' => 'xxxxxx' 
                ), 
                'port' => 587, 
            )); 

            $html = new MimePart('Invitation for the event: Latin Night, orgonized by Mr. Jony Cornillon. Date : 06/04/2015'); 
            $html->type = "text/html"; 

            $body = new MimeMessage(); 
            $body->addPart($html); 
            //$body->setParts(array($html)); 

            $message->setBody($body); 

            $transport->setOptions($options); 
            $transport->send($message); 
        } 
    } 
} 
} 

这是每次显示的错误:

5.1.2 We weren't able to find the recipient domain. Please check for any 
5.1.2 spelling errors, and make sure you didn't enter any spaces, periods, 
5.1.2 or other punctuation after the recipient's email address.    cj9sm2642949wjc.42 - gsmtp

请帮忙。感谢。

0 个答案:

没有答案