Php Symfony2 SwiftMailer don';行不通
我想在我的操作控制器中完成对数据库的插入时使用SwiftMailer发送和发送电子邮件,但不起作用。。 我用swiftmailer做FOSUserBundle,效果很好。。 这是config.yml:Php Symfony2 SwiftMailer don';行不通,php,symfony,send,swiftmailer,mailer,Php,Symfony,Send,Swiftmailer,Mailer,我想在我的操作控制器中完成对数据库的插入时使用SwiftMailer发送和发送电子邮件,但不起作用。。 我用swiftmailer做FOSUserBundle,效果很好。。 这是config.yml: swiftmailer: transport: "%mailer_transport%" host: "%mailer_host%" username: "%mailer_user%" password: "%mailer_password%"
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
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%"
# Routing
be_simple_i18n_routing: ~
# FOSUserBundle Configuration
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Dt\EcBundle\Entity\User
profile:
form:
type: dt_ec_profile
registration:
confirmation:
enabled: true
form:
type: dt_ec_registration
from_email:
address: ------@------.com
sender_name: ------
service:
mailer: fos_user.mailer.twig_swift
resetting:
email:
template: DtEcBundle:User:resetting.email.html.twig
这是控制器的代码:
$container->get('swiftmailer.mailer');
$mailer = \Swift_Mailer::newInstance();
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('------@-----.com')
->setTo('------@-----.com')
->setBody('You should see me from the profiler!')
;
/* // Pass a variable name to the send() method
if (!$mailer->send($message, $failures))
{
echo "Failures:";
var_dump($failures);
} */
$this->get('mailer')->send($message);
/.../
$mailer = $this->get('mailer');
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('------@-----.com')
->setTo('------@-----.com')
->setBody('You should see me from the profiler!')
;
$mailer->send($message);
/.../
我该怎么做???您基本上是在控制器中尝试的吗:
$container->get('swiftmailer.mailer');
$mailer = \Swift_Mailer::newInstance();
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('------@-----.com')
->setTo('------@-----.com')
->setBody('You should see me from the profiler!')
;
/* // Pass a variable name to the send() method
if (!$mailer->send($message, $failures))
{
echo "Failures:";
var_dump($failures);
} */
$this->get('mailer')->send($message);
/.../
$mailer = $this->get('mailer');
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('------@-----.com')
->setTo('------@-----.com')
->setBody('You should see me from the profiler!')
;
$mailer->send($message);
/.../
这是因为在
config.yml
请尝试对这些行进行注释:
spool:
type: file
path: "%kernel.cache_dir%/swiftmailer/spool"
spool会将您的所有电子邮件存储在您的
app/cache/dev/swiftmailer/spool
文件夹中,并等待命令刷新它们。我用这种方式尝试过,但没有任何效果。我现在再试一次,但不起作用@ScoolNico您是否有特定的错误消息或邮件只是没有发送?我解释说,我在我的web项目中有一个消息聊天室,当我发送消息时,控制器会向消息目的地发送一封电子邮件。。但我没有收到任何错误。。。邮件只是没有发送@ScoolNico,正如Julien所说,spool可能是原因。在您的控制台中尝试此命令行,并告诉我们您是否收到消息:php应用程序/控制台swiftmailer:spool:send
不是这个方向的真正乐观主义者,但在config.yml
中尝试disable\u delivery:false
…无。。在这个路径中我没有文件。如何接收错误消息以理解问题的句子@scoolnicoBy跟踪symfony的日志tail-f app/logs/dev
,如果您使用的是linux或其他类似系统。在你的nginx/apacheerror.log上做同样的操作我不知道@Julien Bourdic我看到了Symfony日志,但我真的不明白..截获邮件的另一种方法=>在app/config/config\u dev.yml
:web\u profiler:intercept\u redirects:true
@scoolnico我尝试过但不是好主意。。这不是问题所在。。现在我尝试使用disable_delivery:false