doudian6229 2014-03-21 14:50
浏览 51
已采纳

在Symfony 2中轻松配置SwiftMailer“Local Domain”设置

SwiftMailer is the default way of sending email from a Symfony 2 project, and I'd like to use it in an application. I've pointed it towards the SMTP server provided by my internet provider (Virgin Media, in the UK), but my emails are not successfully sent. The exception thrown says

Expected response code 250 but got code "501", with message "501 HELO requires valid address

in response to the SMTP command

HELO [::1]

[::1] corresponds to localhost in IPv6, and it's not that surprising that the SMTP server would reject that if it's expecting a proper domain name. Tracing execution through the Swiftmailer source, I find that this value comes from _domain on AbstractSmtpTransport; altering the value during the debug session allows the email to be sent. Although it can be set using the public setLocalDomain() method, it isn't anywhere in the Symfony 2 framework, so it seems that there is no way (obvious to me, at least) of easily configuring this value simply by, for example, changing a Symfony config file.

So my question is this: is there some other way of changing this value, ideally using config, without my diving into the Symfony code and changing bits that aren't meant to be changed? And if so, what?

  • 写回答

2条回答 默认 最新

  • dongpao1921 2014-04-07 10:47
    关注

    Unfortunately no.

    The code for get the local domain in SwiftMailer is:

    /** Try to determine the hostname of the server this is run on */
    private function _lookupHostname()
    {
        if (!empty($_SERVER['SERVER_NAME'])
            && $this->_isFqdn($_SERVER['SERVER_NAME']))
        {
            $this->_domain = $_SERVER['SERVER_NAME'];
        } elseif (!empty($_SERVER['SERVER_ADDR'])) {
            $this->_domain = sprintf('[%s]', $_SERVER['SERVER_ADDR']);
        }
    }
    

    So, is guessed and it's server configuration.

    I opened an issue for SwiftMailer to do this:

    https://github.com/swiftmailer/swiftmailer/issues/453

    UPDATE: The issue has been resolved on Feb 27th 2018.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法