使用http://swiftmailer.org时,我可以向邮件队列发送一条消息,以便php立即返回,而不是立即发送消息吗?
我正在使用SwiftMailer捆绑包与Symfony 2.我在config.yml文件中传递我的smtp用户/密码设置,它工作得很好,但是当我发送邮件时,我需要从数据库中取这个设置.我可以访问这个参数:
$mailer = $this->getContainer()->get('mailer')->getTransport();
Run Code Online (Sandbox Code Playgroud)
但是可以在运行时更改它们吗?我没有看到任何setter方法.非常感谢!
我想使用发送网格发送群组消息.我的小组有100个成员.当我发送群组消息时,会传递50到80封消息,然后显示一个空白页面:
NetworkError: 500 Internal Server Error
我的代码是,
set_time_limit (0);
$usernames = 'username'; // Must be changed to your username
$passwords = 'password'; // Must be changed to your password
// Create new swift connection and authenticate
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 25);
$transport ->setUsername($usernames);
$transport ->setPassword($passwords);
$swift = Swift_Mailer::newInstance($transport);
// Create a message (subject)
$message = new Swift_Message($subject);
// add SMTPAPI header to the message
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $hdr->asJSON());
// attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, …Run Code Online (Sandbox Code Playgroud) 我正在使用Gmail帐户作为主机开发一个简单的邮件应用程序.它就像一个魅力,但当send()函数抛出异常时问题就出现了.我看到try catch语句无法处理异常.即使我使用Global异常类,它也不起作用.在某个地方也讨论过这个问题.
例如 :
在Symfony2 dev env控制器中捕获swiftmailer异常
要么
https://groups.google.com/forum/#!topic/symfony2/SlEzg_PKwJw
但他们没有达到工作的答案.
我的控制器功能代码是:
public function ajaxRegisterPublisherAction()
{
//some irrelevant logic
$returns= json_encode(array("username"=>$username,"responseCode"=>$responseCode));
try{
$message = \Swift_Message::newInstance()
->setSubject('hello world')
->setFrom('jafarzadeh91@gmail.com')
->setTo('jafarzadeh991@yahoo.com')
->setBody(
$this->renderView('AcmeSinamelkBundle:Default:email.txt.twig',array('name'=>$username,"password"=>$password))
);
$this->container->get("mailer")->send($message);
}
catch (Exception $e)
{
}
return new \Symfony\Component\HttpFoundation\Response($returns,200,array('Content-Type'=>'application/json'));
}
Run Code Online (Sandbox Code Playgroud)
我在firebug控制台中收到的上述代码发送的响应是:
{"username":"xzdvxvvcvxcv","responseCode":200}<!DOCTYPE html>
<html>
.
.
Swift_TransportException: Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?]
.
.
</html>
Run Code Online (Sandbox Code Playgroud)
我抓住了我的头发,因为我不知道为什么内核在继续我的json对象时处理异常?
当我评论这一行时: …
我在设置Monolog以使用Swiftmailer和Html格式化程序时遇到了麻烦.我有多个monolog处理程序和swiftmail邮件程序可能是问题.这是我的config.yml
独白部分:
services:
monolog.formatter.html:
class: Monolog\Formatter\HtmlFormatter
monolog:
channels: ["orders", "support"]
handlers:
# Called
orders:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%_orders.log"
level: info
channels: orders
# Called
support:
type: fingers_crossed
action_level: critical
handler: support_grouped
channels: support
# Not called, referenced in a handler [support]
support_grouped:
type: group
members: [support_log, environment_log, support_buffered]
# Not called, referenced in a group handler [grouped_support]
support_buffered:
type: buffer
handler: support_buffered_grouped
# Not called, referenced in a handler [support_buffered]
support_buffered_grouped:
type: group
members: [hipchat, webmaster_email, support_email]
# Not called, …Run Code Online (Sandbox Code Playgroud) 我正在编写一个应用程序,使用laravel和swiftmailer向客户端发送邮件,但我得到Process无法启动[系统无法找到指定的路径.]错误.
这是我的代码
环境设置
MAIL_DRIVER = smtp
MAIL_HOST = smtp.gmail.com
MAIL_PORT = 587
MAIL_USERNAME = "*********"
MAIL_PASSWORD = *******
MAIL_ENCRYPTION = tls
Run Code Online (Sandbox Code Playgroud)
调节器
$data = array('name'=>"Virat Gandhi");
Mail::send('emails.mail', $data, function($message) {
$message->to('chuditex2004@yahoo.com', 'Tutorials Point')->subject
('Laravel HTML Testing Mail');
$message->from('chuksdsilent@gmail.com','Virat Gandhi');
});
echo "HTML Email Sent. Check your inbox.";
Run Code Online (Sandbox Code Playgroud)
日志
Swift_TransportException:无法启动进程[系统找不到指定的路径.]在文件
C:\ xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php第299行堆栈跟踪:1.Swift_TransportException - >()C:\ xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php:299 2. Swift_Transport_StreamBuffer-> establishProcessConnection()C:\ xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php:58 3. Swift_Transport_StreamBuffer-> initialize()C:\ xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php:126 4. Swift_Transport_AbstractSmtpTransport-> start() C:\ xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\SendmailTransport.php:52 5. Swift_Transport_SendmailTransport-> start()C:\ xampp\htdocs\tranxavApi\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Mailer.php:67 6. Swift_Mailer-> send()C:\ xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php:451 7. Illuminate\Mail\Mailer-> sendSwiftMessage()C:\ xampp\htdocs\tranxavApi\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php:235 8. …
我已经尝试了几种解决方案,最接近(对我来说)应该是这样的:
$file = $pdf->Output('', 'E');
$message->attach(Swift_Attachment::newInstance($file, 'name.pdf', 'application/pdf'));
Run Code Online (Sandbox Code Playgroud)
$pdf是的实例TCPDF,并$message为实例Swift_Message.使用上面的电子邮件正在发送正常,文件已附加,但当我尝试打开它时,我收到错误消息,文件已损坏或编码错误.
我的问题是:如何将TCPDF生成的pdf作为Swiftmailer附件发送而不将文件保存到服务器并在发送电子邮件后将其删除.这是TCPDF输出方法文档的链接,也许有人可以看到我错过的东西.
我正在尝试在功能测试中测试电子邮件...
控制器:
public function sendEmailAction($name)
{
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('send@example.com')
->setTo('recipient@example.com')
->setBody('You should see me from the profiler!')
;
$this->get('mailer')->send($message);
return $this->render(...);
}
Run Code Online (Sandbox Code Playgroud)
而且测试:
// src/Acme/DemoBundle/Tests/Controller/MailControllerTest.php
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class MailControllerTest extends WebTestCase
{
public function testMailIsSentAndContentIsOk()
{
$client = static::createClient();
// Enable the profiler for the next request (it does nothing if the profiler is not available)
$client->enableProfiler();
$crawler = $client->request('POST', '/path/to/above/action');
$mailCollector = $client->getProfile()->getCollector('swiftmailer');
// Check that an e-mail was sent
$this->assertEquals(1, …Run Code Online (Sandbox Code Playgroud) 我需要禁用ssl证书的验证以用于开发目的,但我在官方文档中没有找到任何相关信息.http://swiftmailer.org/docs/introduction.html
我正在使用php 5.6和Symfony2(v2.7).
SwiftMailerBundle的配置参考是:
swiftmailer:
transport: smtp
username: ~
password: ~
host: localhost
port: false
encryption: ~
auth_mode: ~
spool:
type: file
path: '%kernel.cache_dir%/swiftmailer/spool'
sender_address: ~
antiflood:
threshold: 99
sleep: 0
delivery_address: ~
disable_delivery: ~
logging: '%kernel.debug%'
Run Code Online (Sandbox Code Playgroud) 嗨,我正在使用 php 邮件程序 Swiftmailer 使用 SMTP API 通过 SendGrid 发送。我们可以将唯一参数传递给 SendGrid 以帮助跟踪电子邮件。我已经成功地使用 Swiftmailer 传递了独特的标头:
$headers = $message->getHeaders();
$headers->addTextHeader('AccountId', $accountId);
Run Code Online (Sandbox Code Playgroud)
虽然这些值已成功注入到已发送电子邮件的标头中,但 SendGrid 不会将它们传回我的事件 webhook 或控制面板中。
我也试过这个,这也不起作用:
$headers = $message->getHeaders();
$args = ' {
"customerAccountNumber": "55555",
"activationAttempt": "1",
"New Argument 1": "New Value 1",
"New Argument 2": "New Value 2",
"New Argument 3": "New Value 3",
"New Argument 4": "New Value 4"
}';
$headers->addTextHeader('unique_args', $args);
Run Code Online (Sandbox Code Playgroud)
这可能是 SendGrid 支持的问题,但由于它与 Swiftmailer 相关,我想我会先在这里尝试。谢谢!
swiftmailer ×10
php ×6
symfony ×5
email ×2
codeigniter ×1
laravel-5 ×1
monolog ×1
sendgrid ×1
ssl ×1
tcpdf ×1