我有一個配置了SMTP中繼的Linux服務器。使用命令「mail [email protected]」它可以工作,但是當我使用SwiftMailerBundle時,不會發送郵件。Symfony2 SwiftMailer不發送
日誌:
[2014-03-14 10:01:06] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand". [] []
[2014-03-14 10:01:06] event.DEBUG: Notified event "console.terminate" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onTerminate". [] []
[2014-03-14 10:01:06] event.DEBUG: Notified event "console.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onTerminate". [] []
Parameters.yml:
mailer_transport: mail
mailer_host: localhost
mailer_user: myusername
mailer_password: ********
我的命令:
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class AbsenceCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('absence:absence')
->setDescription('Envoi des absences aux parents')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody("Test")
;
$this->getContainer()->get('mailer')->send($message);
$mailer = $this->getContainer()->get('mailer');
$transport = $mailer->getTransport();
if ($transport instanceof \Swift_Transport_SpoolTransport) {
$spool = $transport->getSpool();
$sent = $spool->flushQueue($this->getContainer()->get('swiftmailer.transport.real'));
}
$output->writeln("E-mail envoyé aux parents des apprentis !");
}
}
你對溶液中的任何想法?
問候!
這是什麼?我沒有此服務器上的管理員權限。 – Servietsky
@Servietsky:在這種情況下,您可能已經安裝了郵件服務器。嘗試通過Outlook,Thunderbird或任何其他方式連接到您的服務器,以確保您的郵件服務已啓動並正在收聽,並且您的憑證正常工作。 –