Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法使用SwiftMailer和Symfony 2发送电子邮件_Php_Symfony_Email_Swiftmailer - Fatal编程技术网

Php 无法使用SwiftMailer和Symfony 2发送电子邮件

Php 无法使用SwiftMailer和Symfony 2发送电子邮件,php,symfony,email,swiftmailer,Php,Symfony,Email,Swiftmailer,我正在尝试使用SwiftMailer和Symfony2发送电子邮件 之前我有一个无法连接到smtp.gmail.com的问题,但是我知道,我没有任何错误,但是消息仍然没有发送 这是我的配置.yml: swiftmailer: transport: mail encryption: ssl host: smtp.gmail.com port: 465 auth_mode: login username: myUsername@gmail.com

我正在尝试使用SwiftMailer和Symfony2发送电子邮件

之前我有一个
无法连接到smtp.gmail.com
的问题,但是我知道,我没有任何错误,但是消息仍然没有发送

这是我的配置.yml

swiftmailer:
    transport: mail
    encryption: ssl
    host: smtp.gmail.com
    port: 465
    auth_mode: login
    username:   myUsername@gmail.com
    password:   myPassword
swiftmailer:
    disable_delivery: false
$message = \Swift_Message::newInstance(null)
   ->setSubject('Test')
   ->setFrom('test@gmail.com')
   ->setTo('test@gmail.com')
   ->setBody('Test test test !!');

$this->get('mailer')->send($message);
配置测试.yml

swiftmailer:
    transport: mail
    encryption: ssl
    host: smtp.gmail.com
    port: 465
    auth_mode: login
    username:   myUsername@gmail.com
    password:   myPassword
swiftmailer:
    disable_delivery: false
$message = \Swift_Message::newInstance(null)
   ->setSubject('Test')
   ->setFrom('test@gmail.com')
   ->setTo('test@gmail.com')
   ->setBody('Test test test !!');

$this->get('mailer')->send($message);
要发送的控制器

swiftmailer:
    transport: mail
    encryption: ssl
    host: smtp.gmail.com
    port: 465
    auth_mode: login
    username:   myUsername@gmail.com
    password:   myPassword
swiftmailer:
    disable_delivery: false
$message = \Swift_Message::newInstance(null)
   ->setSubject('Test')
   ->setFrom('test@gmail.com')
   ->setTo('test@gmail.com')
   ->setBody('Test test test !!');

$this->get('mailer')->send($message);
我尝试了许多在互联网上找到的修复方法,但都没有解决:/

我正在尝试使用本地Wamp发送它

编辑:

swiftmailer:
transport: smtp
encryption: ssl     
auth_mode:  login   
host: "%mailer_host%"
username:  "%mailer_user%"
password:  "%mailer_password%"
spool:     { type: memory }
 mailer_transport: gmail
    mailer_host: smtp.gmail.com
    mailer_user: yourmail@gmail.com
    mailer_password: your_mail_password
public function sendMailAction() { 

      $Request= $this ->getRequest();

      if($Request ->getMethod()== "POST"){

          $name= $Request -> get("name");
          $email = $Request -> get("email");
          $sujet = $Request -> get("subject");
          $message = $Request -> get("message");

          $mailer = $this->container->get('mailer');
          $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
                  ->setUsername('******')
                  ->setPassword('******');

           $sms = \Swift_Message::newInstance('Test')
                   ->setSubject($sujet)
                   ->setFrom('your_mail_here@gmail.com')
                   ->setTo($email)
                   ->setBody($message);

$spool = $mailer->getTransport()->getSpool();
$transport = $this->get('swiftmailer.transport.real');

$spool->flushQueue($transport);
           $this->get('mailer')->send($sms);

      }
      return $this->render('SwiftMailSwiftMailBundle:Mail:contact.html.twig');   

      }
我已经将传输设置为SMTP,现在,当我使用端口443时,我得到一个超时,如果我使用465,我只会再次得到“无法连接”

编辑2:

swiftmailer:
transport: smtp
encryption: ssl     
auth_mode:  login   
host: "%mailer_host%"
username:  "%mailer_user%"
password:  "%mailer_password%"
spool:     { type: memory }
 mailer_transport: gmail
    mailer_host: smtp.gmail.com
    mailer_user: yourmail@gmail.com
    mailer_password: your_mail_password
public function sendMailAction() { 

      $Request= $this ->getRequest();

      if($Request ->getMethod()== "POST"){

          $name= $Request -> get("name");
          $email = $Request -> get("email");
          $sujet = $Request -> get("subject");
          $message = $Request -> get("message");

          $mailer = $this->container->get('mailer');
          $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
                  ->setUsername('******')
                  ->setPassword('******');

           $sms = \Swift_Message::newInstance('Test')
                   ->setSubject($sujet)
                   ->setFrom('your_mail_here@gmail.com')
                   ->setTo($email)
                   ->setBody($message);

$spool = $mailer->getTransport()->getSpool();
$transport = $this->get('swiftmailer.transport.real');

$spool->flushQueue($transport);
           $this->get('mailer')->send($sms);

      }
      return $this->render('SwiftMailSwiftMailBundle:Mail:contact.html.twig');   

      }
我试图使用“传输:gmail”,但仍然“无法连接”信息 这是我的配置:

transport: gmail
username:  'myEmail@gmail.com'
password:  'myPassword'

要使用Gmail发送邮件,您可以使用
transport:Gmail

如果您需要更多信息:


如果配置良好且不起作用,请在App/config/config.yml中检查您的安全环境(防火墙等)

,您可以这样写:

swiftmailer:
transport: smtp
encryption: ssl     
auth_mode:  login   
host: "%mailer_host%"
username:  "%mailer_user%"
password:  "%mailer_password%"
spool:     { type: memory }
 mailer_transport: gmail
    mailer_host: smtp.gmail.com
    mailer_user: yourmail@gmail.com
    mailer_password: your_mail_password
public function sendMailAction() { 

      $Request= $this ->getRequest();

      if($Request ->getMethod()== "POST"){

          $name= $Request -> get("name");
          $email = $Request -> get("email");
          $sujet = $Request -> get("subject");
          $message = $Request -> get("message");

          $mailer = $this->container->get('mailer');
          $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
                  ->setUsername('******')
                  ->setPassword('******');

           $sms = \Swift_Message::newInstance('Test')
                   ->setSubject($sujet)
                   ->setFrom('your_mail_here@gmail.com')
                   ->setTo($email)
                   ->setBody($message);

$spool = $mailer->getTransport()->getSpool();
$transport = $this->get('swiftmailer.transport.real');

$spool->flushQueue($transport);
           $this->get('mailer')->send($sms);

      }
      return $this->render('SwiftMailSwiftMailBundle:Mail:contact.html.twig');   

      }
在App/config/parameters.yml:

swiftmailer:
transport: smtp
encryption: ssl     
auth_mode:  login   
host: "%mailer_host%"
username:  "%mailer_user%"
password:  "%mailer_password%"
spool:     { type: memory }
 mailer_transport: gmail
    mailer_host: smtp.gmail.com
    mailer_user: yourmail@gmail.com
    mailer_password: your_mail_password
public function sendMailAction() { 

      $Request= $this ->getRequest();

      if($Request ->getMethod()== "POST"){

          $name= $Request -> get("name");
          $email = $Request -> get("email");
          $sujet = $Request -> get("subject");
          $message = $Request -> get("message");

          $mailer = $this->container->get('mailer');
          $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
                  ->setUsername('******')
                  ->setPassword('******');

           $sms = \Swift_Message::newInstance('Test')
                   ->setSubject($sujet)
                   ->setFrom('your_mail_here@gmail.com')
                   ->setTo($email)
                   ->setBody($message);

$spool = $mailer->getTransport()->getSpool();
$transport = $this->get('swiftmailer.transport.real');

$spool->flushQueue($transport);
           $this->get('mailer')->send($sms);

      }
      return $this->render('SwiftMailSwiftMailBundle:Mail:contact.html.twig');   

      }
在控制器中:

swiftmailer:
transport: smtp
encryption: ssl     
auth_mode:  login   
host: "%mailer_host%"
username:  "%mailer_user%"
password:  "%mailer_password%"
spool:     { type: memory }
 mailer_transport: gmail
    mailer_host: smtp.gmail.com
    mailer_user: yourmail@gmail.com
    mailer_password: your_mail_password
public function sendMailAction() { 

      $Request= $this ->getRequest();

      if($Request ->getMethod()== "POST"){

          $name= $Request -> get("name");
          $email = $Request -> get("email");
          $sujet = $Request -> get("subject");
          $message = $Request -> get("message");

          $mailer = $this->container->get('mailer');
          $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
                  ->setUsername('******')
                  ->setPassword('******');

           $sms = \Swift_Message::newInstance('Test')
                   ->setSubject($sujet)
                   ->setFrom('your_mail_here@gmail.com')
                   ->setTo($email)
                   ->setBody($message);

$spool = $mailer->getTransport()->getSpool();
$transport = $this->get('swiftmailer.transport.real');

$spool->flushQueue($transport);
           $this->get('mailer')->send($sms);

      }
      return $this->render('SwiftMailSwiftMailBundle:Mail:contact.html.twig');   

      }

如果您愿意,请让我向您发送完整的项目。祝您好运

我试了443465,25。没什么变化我也检查了我的垃圾邮件传输参数应该是“smtp”而不是“mail”?我没有任何错误,只是没有收到电子邮件。我将编辑有关新信息的问题。我的gmail帐户应该配置为。。。我怎么能检查?我已经试过了,并检查了这个链接。。。“无法连接”。我会更新我的问题,让你看看我做了什么,我看到@carndacier,你在当地环境中工作了吗。如果是,您是否有防火墙或服务器管理员?我正在本地环境中测试它是的。我会通过停用avastI来检查我很笨。。。我禁用了Avast,它现在可以工作了。。。谢谢,伙计