使用swiftmailer向多个收件人发送电子邮件 [英] Sending email to multiple Recipients with swiftmailer

查看:232
本文介绍了使用swiftmailer向多个收件人发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在项目中使用swiftmailer,以便可以将html新闻稿发送给多个用户。我已经进行了彻底的搜索,但是所有我从未为我工作。我想在用逗号分隔的表单输入字段中粘贴多个收件人,并将html电子邮件发送给他们。
我将收件人设置为变量($ recipients_emails)并将其传递给发送代码中的setTo()方法,与相同html_email

I am trying to use swiftmailer in my project so that I can send html newsletter to multiple users. I have searched thoroughly but all i got never worked for me. I want to paste more than one recipient in the form input field seperated by comma and send the html email to them. I set the recipients to a variable($recipients_emails) and pass it to setTo() method in the sending code, same with the html_email.

问题是:
问题1我如何从收件人输入字段发送给多个收件人。

Questions are: Q1 How do i send to more than one recipient from the recipient input field.

我尝试过:

if (isset($_POST['recipients_emails'])) {
    $recipients_emails  = array($_POST['recipients_emails'] );
    $recipients_emails= implode(',',$recipients_emails);
}

Q2如何在Html中使用Html。当我尝试像这样-> setBody('<<< EOT'。$ html_email.'EOT;','text / html'); 串联时,我的消息将带有heredoc标签。

Q2 How do I make the Html within heredoc tag. when i tried concatenating like this ->setBody('<<<EOT'.$html_email.'EOT;', 'text/html'); , my message would appears with the heredoc tag.

if (isset($_POST['html_email'])) {
    $html_email = $_POST['html_email'];
}

如何从 $ _ POST []输入信息html_email']; 放在EOT标记内;

How do I have input from $_POST['html_email']; to be within EOT tag;

这是swiftmailer发送脚本的一部分;

this in part of swiftmailer sending script ;

$message = Swift_Message::newInstance()
        ->setSubject($subject)
        ->setFrom($from)
        ->setTo($recipients_emails)
        ->setBody($html_email, 'text/html');

Nota bene:我还在学习这些东西。

Nota bene : Am still learning these things.

推荐答案

根据此文档

// Using setTo() to set all recipients in one go
$message->setTo([
  'person1@example.org',
  'person2@otherdomain.org' => 'Person 2 Name',
  'person3@example.org',
  'person4@example.org',
  'person5@example.org' => 'Person 5 Name'
]);

您可以将数组直接输入到setTo,setCc或setBcc函数中,不需要将其转换为字符串

You can input array directly into setTo, setCc or setBcc function, do not need to convert it into string

这篇关于使用swiftmailer向多个收件人发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆