我正在尝试创建一封电子邮件,用于向与特定公司绑定的所有用户发送邮件。如果我将收件人数组添加到我的电子邮件并使用一封电子邮件进行测试,则可以在测试电子邮件中看到所有用户电子邮件。当我尝试过的,而不是使用一个单一的电子邮件地址,我得到一个消息同一收件人数组setTo“警告:非法偏移类型”使用symfony对象发送Swift_message
$company = $this->getDoctrine()->getRepository('Bundle:Customer')->findOneBy(array('accountId' => $compare->getCustomerAccount()));
$recipients = [];
foreach($company->getUsers() as $user){
array_push($recipients, $user);
}
array_push($recipients, $company->getCsr());
$newComment = new Comment();
$newComment->setDetails($comment);
$newComment->setUser($this->getUser());
$em = $this->getDoctrine()->getManager();
$em->flush();
$message = \Swift_Message::newInstance()
->setSubject($subject)
->setFrom($fromEmail)
->setTo($recipients)
->setBody(
$this->renderView(
'Bundle:Comment:email_users.html.twig', array(
'subject' => $subject,
'comment' => $comment,
'company' => $company,
'proof' => $proof
)
)
)
->setContentType('text/html')
;
$this->get('mailer')->send($message);
看起来你在推用户对象而不是电子邮件地址? – ccKep
@ccKep yup,如何访问symfony用户对象的电子邮件? getEmail不是一个函数。 –
那么,如果您打算向他们发送邮件,您必须将电子邮件存储在某个地方?你的用户实体是什么样的? – ccKep