Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Pages: 1
Hello, I'm trying to send an e-mail to multiple e-mail address in my database. Here is my current code. It is only working when I specify a single e-mail address, however, I need to have them query my database and send the e-mail to each e-mail address. Where am I going wrong here?
[lang=php] $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, 'eee@web.com') ->addFrom('xxxx@gmail.com') ->setSubject('Invitation à l’événement : Soirée Latino'); $message->addCc('xxxx@hotmail.com') ->addBcc("xxxx@hotmail.com"); // 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' => 'xxxx@gmail.com', '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); }
And this is the error:
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
Any help please. Thanks.
Hors ligne
hi,
i try a test with your request, this is my result :
[lang=php] $mails = array( 0 => array('email' => 'blabla.com'), 1 => array('email' => 'test.fr'), );
so check your's
Hors ligne
Thanks flobrflo, i find the solution and this is the code:
[lang=php]foreach ($mail as $recip) { $message->addTo($recip); $message->addTo('samehmay@hotmail.com', 'eee@web.com') ->addFrom('maysameh0@gmail.com') ->setSubject('Invitation à l’événement : Soirée Latino'); }
Hors ligne
Pages: 1