从官方 Swift Mailer 组交叉发布....
我正在尝试使用 Swift Mailer 包和文件假脱机发送电子邮件,但是当我告诉控制台发送邮件时,它告诉我假脱机中有 0 条消息。假脱机应该由 Swift Mailer 自动创建,还是我需要手动创建文件?因为我在任何地方都看不到假脱机文件。
我的 config.yml:
# Swiftmailer Configuration
swiftmailer:
transport: sendmail
host: /usr/bin/sendmail
username: %mailer_user%
password: %mailer_password%
spool:
type: file
path: "%kernel.root_dir%/spool"
我如何发送邮件:
public function contactAction(Request $request)
{
$form = $this->createFormBuilder()
->add('name', 'text', array('label' => 'Name:'))
->add('email', 'email', array('label' => 'Email Address:'))
->add('subject', 'text', array('label' => 'Subject:'))
->add('message', 'textarea', array('label' => 'Message:'))
->getForm();
if ($request->isMethod('POST')) {
$form->bind($request);
$data = $form->getData();
if (!empty($data['name'])) {
$data['message'] = str_replace("\n.", "\n..", $data['message']);
$emailValidator = new Email();
$emailValidator->message = "Invalid email address";
$error = $this->get('validator')->validateValue($data['email'], $emailValidator);
if (count($error) == 0) {
$mail = \Swift_Message::newInstance()
->setSubject($data['subject'])
->setFrom('mail@mysite.com')
->setTo('me@myrealaddress.com')
->setBody($data['message']);
$this->get('mailer')->send($mail);
return $this->redirect($this->generateUrl('_success'));
} else {
return $this->redirect($this->generateUrl('_failure'));
}
}
}
我究竟做错了什么?根据 Symfony 文档,这应该可以工作。