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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化