【问题标题】:Connection could not be established when sending swiftmailer email through symfony2通过 symfony2 发送 swiftmailer 电子邮件时无法建立连接
【发布时间】:2014-04-03 08:01:50
【问题描述】:

每次我尝试在 symfony 2.3.11 中使用 swiftmailer 通过 google 应用程序帐户发送电子邮件时,都会收到以下消息

无法与主机 smtp.gmail.com 建立连接 [php_network_getaddresses:getaddrinfo失败:临时失败 名称解析 #0] 500 内部服务器错误 - Swift_TransportException

我用谷歌搜索了它,但我没有得到任何结果,所以我一定是做错了什么。

config.yml

# Swiftmailer Configuraftion swiftmailer:
    transport:  gmail
    username:   info@*******.com
    password:   **

发送电子邮件的控制器:

/* send an email to user */
$message = \Swift_Message::newInstance()
    ->setSubject('Thank you')
    ->setFrom('info@********.com')
    ->setTo($email)
    ->setBody(
    $this->renderView(
        'xyProfileBundle:Mailer:thankyou.html.twig', 
        array('email' => $email, 'token' => $token)
        )
    )
    ->setContentType("text/html");
$this->get('mailer')->send($message);

我该如何解决这个问题?

【问题讨论】:

  • 您的swiftmailer配置不完整。请完成它。你在开发环境吗?使用 gmail 作为传输使用特定端口,确保它们没有关闭 :-)。
  • Symfony 食谱说您只定义“gmail”而不是主机和端口。它们是自动提供的。

标签: php symfony google-apps symfony-2.3 swiftmailer


【解决方案1】:

您的主机似乎无法解析 smtp.gmail.com。

尝试 ping 它:

ping smtp.gmail.com

还有:

 php -r 'var_dump(gethostbyname("smtp.gmail.com"));'

【讨论】:

  • 谢谢,纳吉——至少我找到了问题的根源。 Apache 从 ubuntu 服务器 vm 内部运行,似乎 dns 配置错误。
  • 你是如何配置它的@Radolino?
【解决方案2】:

尝试使用IP地址74.125.206.109代替域名(smtp.gmail.com)

【讨论】:

    猜你喜欢
    • 2023-03-08
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多