标签: swiftmailer

使用SwiftMailer批量发送电子邮件

我目前正在使用SwiftMailer向几个用户发送电子邮件(最多50个).我已经设置并正常工作,但是,我不太确定如何从MySQL数据库中提取收件人并迭代发送它们.

这是我目前拥有的:

<?php  
require_once 'swift/lib/swift_required.php';
$mailer = Swift_Mailer::newInstance(
Swift_SmtpTransport::newInstance('smtp.connection.com', 25)  
->setUsername('myUserName')
->setPassword('myPassword')
 );

 $mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(9));

 $message = Swift_Message::newInstance()

  ->setSubject('Let\'s get together today.')

  ->setFrom(array('myfrom@domain.com' => 'From Me'))

  ->setTo(array('tom_jones@domain.com' => 'Tom Jones', 'jsmith@domain.com' => 'Jane Smith', 'j_doe@domain.com' => 'John Doe', 'bill_watson@domain.com' => 'Bill Watson',))

  ->setBody('Here is the message itself')
  ->addPart('<b>Test message being sent!!</b>', 'text/html')
   ;

  $numSent = $mailer->batchSend($message, $failures);

  printf("Sent %d messages\n", $numSent);
Run Code Online (Sandbox Code Playgroud)

如上所示,在setTo中,我想从数据库中的用户进行迭代.就像是:

SELECT first, last, email FROM users WHERE is_active=1

文件规定:

Note: Multiple calls to setTo() …

php mysql scripting swiftmailer

6
推荐指数
1
解决办法
7128
查看次数

使用Gmail for SMTP时,您可以设置不同的"发件人"地址吗?

我正在使用Swift Mailer 406发送电子邮件.我连接到我的smtp.gmail.com帐户然后我这样做:

->setFrom(array($from => $fromname))
Run Code Online (Sandbox Code Playgroud)

但发送的电子邮件收到了原始的Gmail帐户电子邮件.

我可以改变吗?

php email gmail smtp swiftmailer

6
推荐指数
1
解决办法
8780
查看次数

SwiftMailer是否支持以Mail_Queue的方式发送异步邮件?

我想使用sendgrid的SMTP服务器发送我的电子邮件,但是要连接到它们,而不是"网络时间",而是通过(简单)队列.

我知道PEAR的Mail_Queue可以让我这样做,但我可以使用SwiftMailer吗?

(SwiftMailer和Mail_Queue之间究竟有哪些区别?)

谢谢!

swiftmailer mail-queue

6
推荐指数
1
解决办法
1652
查看次数

在CakePHP中接收/检索电子邮件

我正在为一个小型培训中心开发一个基本但高度定制的CRM,该培训中心能够存储学生记录并向他们发送电子邮件.我正在使用SwiftMailer遵循CakePHP中的这个优秀教程来完成发送部分.

当然,学生有时会回复电子邮件,我想在我的CRM中检索它们并将它们与学生记录一起存储.

但是,我找不到这样做的单一参考.我尝试了以下谷歌搜索:"接收电子邮件cakephp","检索电子邮件cakephp",甚至"电子邮件客户端cakephp",但所有这些查询都给出了发送邮件而不是接收邮件的结果- 非常令人沮丧!

最后,我将搜索范围扩展到非蛋糕解决方案,并发现有人推荐了一个名为ezComponents的库.它似乎没有任何活跃的开发大约一年,但它包括一个电子邮件接收类,这正是我想要的.不幸的是,我不知道如何将它添加到CakePHP中,我在整个网络上找到的唯一一篇关于此事的帖子并没有详细说明.这肯定不是在CakePHP上使用ezComponents的分步教程,就像我上面提到的SwiftMailer教程一样.

我还在Google Code上找到了一个名为php-imap的课程,看起来它可以完成这项工作,但是,我还没有丝毫的线索如何让它像SwiftMailer一样快乐地在Cake中工作.

我意识到我可能必须自己学习如何打包用于Cake的类,但是我首先要问的是这个问题已经存在,我已经没有意识到这个问题我已经没有实现这个问题了. :-)

约瑟夫

cakephp swiftmailer

6
推荐指数
1
解决办法
5397
查看次数

Swift-Mailer错误,"给出[]邮箱中的地址不符合RFC"

我已经构建了一个简单的PHP联系表单,该表单应该通过Swift-Mailer脚本发送邮件.

问题是我一直收到这个错误

带有消息'给出邮箱中的地址[]的未捕获异常'Swift_RfcComplianceException'不符合RFC 2822,3.6.2.

我想这意味着我使用的是无效的电子邮件地址.但由于我使用myaddress@gmail.com来测试脚本,问题可能就在其他地方.这是我的配置:

邮件发送到的地方:

$my_mail = 'mymail@mydomain.com';
$my_name = 'My Name';
Run Code Online (Sandbox Code Playgroud)

消息内容:

$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);
$date = date('d/m/Y H:i:s'); 
$ipaddress = $_SERVER['REMOTE_ADDR'];  

$content = $message.'\n\nSent on: '.$date.' From: '.$ipaddress;
Run Code Online (Sandbox Code Playgroud)

我用来使用swiftmailer发送邮件的功能:

function send_mail () {
require('/path/to/swift_required.php');

//The means of transport
$transport = Swift_SmtpTransport::newInstance('mail.mydomain.com', 25);
$transport->setUsername('myusername');
$transport->setPassword('mypass');

$mailer = Swift_Mailer::newInstance($transport);

//The message
$mail = Swift_Message::newInstance();
$mail->setSubject('Hello');
$mail->setFrom(array($email => $name ));
$mail->setTo(array($my_mail => $my_name));
$mail->setBody($content, 'text/plain');

//Sending the message
$test = $mailer->send($mail);

if ($test) { …
Run Code Online (Sandbox Code Playgroud)

php email swiftmailer

6
推荐指数
1
解决办法
2万
查看次数

CakePHP SwiftMailer SMTP TLS OpenSSL错误SSL3_GET_RECORD:错误的版本号

我正在尝试使用我在此处找到的CakePHP SwiftMailer组件发送电子邮件:http: //bakery.cakephp.org/articles/sky_l3ppard/2009/11/07/updated-swiftmailer-4-xx-component-with-attachments -and-插件

我发送到的服务器使用带有TLS的SMTP通过端口25.这是我尝试发送邮件时出现的错误:

Notice (8): Trying to get property of non-object [APP/views/helpers/hdl_session.php, line 14]

Warning (2): stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number [CORE/vendors/classes/Swift/Transport/StreamBuffer.php, line 271]

Warning (2): stream_socket_client() [function.stream-socket-client]: Failed to enable crypto [CORE/vendors/classes/Swift/Transport/StreamBuffer.php, line 271]

Warning (2): stream_socket_client() [function.stream-socket-client]: unable to connect to tls://mail.aedisit.com:25 (Unknown error) [CORE/vendors/classes/Swift/Transport/StreamBuffer.php, line 271]

Warning (2): Illegal offset type in isset or empty [CORE/cake/libs/i18n.php, line 177]

Warning (2): Cannot modify header …
Run Code Online (Sandbox Code Playgroud)

php ssl openssl smtp swiftmailer

6
推荐指数
1
解决办法
6047
查看次数

可以在localhost上使用swiftMailer发送电子邮件吗?

我目前没有收到使用以下配置的电子邮件,并且想知道是否与我的设置有关可能遗漏了某些内容或者它在MAMP localhost上无法正常工作?

common-local.php在common config目录下

    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        // send all mails to a file by default. You have to set
        // 'useFileTransport' to false and configure a transport
        // for the mailer to send real emails.
        'useFileTransport' => true,
    ],
Run Code Online (Sandbox Code Playgroud)

然后发送电子邮件(显示成功消息)

public function submitreview($email)
{
    //return Yii::$app->mailer->compose(['html' => '@app/mail-templates/submitreview'])
    return Yii::$app->mailer->compose()
        ->setTo($email)
        ->setFrom([$this->email => $this->name])
        ->setSubject($this->title)
        ->setTextBody($this->description)
        ->attachContent($this->file)
        ->send();
}
Run Code Online (Sandbox Code Playgroud)

php swiftmailer yii2

6
推荐指数
1
解决办法
7982
查看次数

SwiftMailer,PhpMailer等:mail()和sendmail之间的区别

我经常读到PHP的mail() -Function在内部使用sendmail.

那么为什么像SwiftMailer,PhpMailer等邮件库让我们有机会在mail()sendmail之间做出选择?

这不是一回事吗?

没听过有人说这不是一回事!

请帮忙,因为我真的很困惑!

php email sendmail phpmailer swiftmailer

6
推荐指数
1
解决办法
4911
查看次数

Swiftmailer:无法连接TLS加密

我正在尝试使用Swiftmailer通过Symfony发送电子邮件.在生产服务器上,我收到一个错误:

[2016-08-20 11:59:37] app.ERROR: Exception occurred while flushing email queue: Unable to connect with TLS encryption [] []
Run Code Online (Sandbox Code Playgroud)

这是我在config.yml中的内容:

swiftmailer:
transport: smtp
host:      localhost
username:  info@derkvanderheide.nl
password:  testpw
spool:     { type: memory }
encryption: tls
port:       587
Run Code Online (Sandbox Code Playgroud)

Postfix是我的邮件服务器,它与Plesk一起安装.

这是我的postfix main.cf:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname …
Run Code Online (Sandbox Code Playgroud)

php plesk swiftmailer symfony postfix

6
推荐指数
1
解决办法
7393
查看次数

Symfony 4 SwiftMailer Gmail:未发送电子邮件

我目前正在研究Symfony 4应用程序,我需要通过Swift Mailer发送电子邮件.当我发送电子邮件时,我收到假脱机电子邮件,但我没有收到我的Gmail邮箱.我允许在我的Gmail配置中使用不安全的应用程序.

这是来自.env文件的邮件程序URL:MAILER_URL = gmail://ep****@gmail.com:PASSWORD @ localhost

这是我的swiftmailer.yaml:

    #config/packages/swiftmailer.yaml
    swiftmailer:
        url: '%env(MAILER_URL)%'
        spool: { type: 'memory' }
Run Code Online (Sandbox Code Playgroud)

这是我的控制器功能:

SRC /控制器/ AccountController.php

完成表格后

这是我遵循的文档:http: //symfony.com/doc/current/email.html

我已经检查了这些问题,但他们没有给我答案:如何从运行在Windows 10上的本地计算机上发送带有Symfony 4 Swiftmailer的电子邮件?,邮件symfony 4无法正常工作

拜托,我需要帮助.我整天都在寻找解决方案.我没有错,但我没有收到邮件.提前致谢.任何链接都可以帮助我.

php gmail swiftmailer symfony4

6
推荐指数
1
解决办法
1万
查看次数