问题描述
我无法发送相同的邮件到多个收件人从数据库中恢复,使用zend框架2.与我的解决方案,我只能发送电子邮件到我的数据库的第一行,我不知道是什么问题。
这是我在indexController中的操作:
i wan't to send the same mail to multiple recipients retreived from database, using zend framework 2. With my solution i can only send email to the first row on my database, and i do not no what's the problem exactly.This is my action in the 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');
$mail = $db->query("SELECT * FROM user")->execute()->current();
print_r($mail);
exit();
$message = new Message();
foreach ($mail as $recip) {
$message->addTo($recip)
->addFrom('[email protected]')
->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' => '[email protected]',
'password' => 'xxxxxx'
),
'port' => 587,
));
$html = new MimePart('<b>Invitation for the event: Latin Night, orgonized by Mr. Jony Cornillon. Date : 06/04/2015</b>');
$html->type = "text/html";
$body = new MimeMessage();
$body->addPart($html);
//$body->setParts(array($html));
$message->setBody($body);
$transport->setOptions($options);
$transport->send($message);
}
}
}
}
也当我把 printr($ mail); exit();
显示结果,只有第一行将显示在页面上。任何帮助。
And also when i put printr($mail); exit();
to show the result, only the first line will be displayed on the page. Any help please.
推荐答案
我找到另一个解决方案,我可以成功地显示所有来自数据库的电子邮件 print_r
。但是现在当我把结果集放在 message-> addTo()
时,会显示一个错误。这是我的新代码
i find another solution and i can succefully diplay all emails from database with print_r
. However now when i put the resultset on the message->addTo()
, an error will diplay. This is my new code
$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('[email protected]', '[email protected]')
->addFrom('[email protected]')
->setSubject('Invitation for the event : Event Latino');
}
任何帮助。谢谢。
这篇关于从DB zend 2向多个收件人发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!