Php 信条:通过SwiftMailer发送假脱机电子邮件

Php 信条:通过SwiftMailer发送假脱机电子邮件,php,email,symfony,doctrine-orm,swiftmailer,Php,Email,Symfony,Doctrine Orm,Swiftmailer,我正在尝试使用Symfony上的SwiftMailer捆绑包发送电子邮件。我可以通过以下命令发送邮件: swiftmailer:email:send From: myemail To: emailRecipient Subject: Hi Body: This is a test Sent 1 emails Done. 提交表格后,我想发送电子邮件。我可以在我的生产服务器上看到它们: /home/sga/www/app/spool/default 因此,我尝试使用以下方式发送它们:

我正在尝试使用Symfony上的SwiftMailer捆绑包发送电子邮件。我可以通过以下命令发送邮件:

swiftmailer:email:send    
From: myemail
To: emailRecipient
Subject: Hi
Body: This is a test
Sent 1 emails
Done.
提交表格后,我想发送电子邮件。我可以在我的生产服务器上看到它们:

/home/sga/www/app/spool/default
因此,我尝试使用以下方式发送它们:

swiftmailer:spool:send --env=prod
最后我得到:

Processing default mailer... 0 emails sent
Done.

swiftmailer:debug"
[swiftmailer] Current mailers
Name                     Transport Spool Delivery Single Address
default (default mailer) smtp      YES   YES   
My config.yml文件:

# Swiftmailer Configuration
swiftmailer:
    transport: smtp
    host:      myhost
    username:  ~
    password:  ~
    spool:
        type: file
        path: "%kernel.root_dir%/spool"

我不知道为什么不发送电子邮件

原来是我的gmail收件人地址造成的。 也许gmail将我的电子邮件地址归类为垃圾邮件,或者拒绝发送我的邮件。但我的gmail垃圾邮件文件夹里什么都没有

编辑:

它拒绝为没有相同主机的所有地址发送电子邮件。 例如:它只发送带有@example.com的电子邮件 因此:

但是:

->setFrom('x.y@example.com')
->setTo('x.y@example.com')
is working
作为剩余部分:

$transport = \Swift_SmtpTransport::newInstance("smtp.example.com", 25);
    $transport->setUsername("xxx");
    $transport->setPassword("YYYY");

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

    $message = \Swift_Message::newInstance()
            ->setSubject($subject)
            ->setContentType("text/plain; charset=UTF-8")
            ->setFrom('x.y@example.com')
            ->setTo('x.y@gmail.com')
            ->setBody($body, 'multipart/alternative')
            ->addPart($body, 'text/html')
            ->addPart($bodyPlain, 'text/plain');
    if (!$mailer->send($message, $failures)) {
        echo "Failures:";
        print_r($failures);
    }
我的失败是:

Failures:Array ( [0] => x.y@gmail.com ) 

最后我刚换了交通工具:

swiftmailer:
transport: sendmail
host:      /usr/bin/sendmail
username:  ~
password:  ~
spool:     { type: memory }

我的电子邮件未使用Symfony命令发送,但我仍然遇到向gmail地址发送电子邮件失败的问题。

您的邮件是否保存到
%kernel.root\u dir%/spool
?Maaybe这是一个文件权限问题,您的应用程序无法写入此文件?是的。我检查了权限文件:spool/default有0755,但我的电子邮件有644。我试图更改权限,但它说我无法更改,因为“权限被拒绝”。所有者是www数据。。您知道如何更改文件权限吗?
swiftmailer:
transport: sendmail
host:      /usr/bin/sendmail
username:  ~
password:  ~
spool:     { type: memory }