2015-03-31 103 views
0

這是我使用Zend Framework 2的第一個應用程序。我想發送一封電子郵件給從數據庫中收回的收件人,但每次我的代碼都顯示錯誤。這是我的代碼:使用zf2從數據庫發送郵件給多個收件人

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

if (!$user->offsetExists('id')) { 
    $idconnected = '0';   
} else { 
    $idconnected = $user->offsetGet('id'); 
    $mail = $db->query("SELECT email FROM user WHERE id =" . $idconnected)->execute()->current(); 

    $message = new Message(); 
    $message->addTo($mail, '[email protected]') 
      ->addFrom('[email protected]') 
      ->setSubject('Invitation à l’événement : Soirée Latino'); 
    $message->addCc('[email protected]') 
      ->addBcc("[email protected]"); 

    // 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' => '[email protected]', 
      'password' => '*********' 
     ), 
     'port' => 587, 
    )); 
    $html = new MimePart('<b>Invitation for the event: Latin Night, orgonized by Mr. Jony Cornillon <i>Date : 06/04/2015</i></b>'); 
    $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. a13sm19808164wjx.30 - gsmtp 

回答

相關問題