【问题标题】:Send mail only if fsockopen is connected to SMTP Server仅当 fsockopen 连接到 SMTP 服务器时才发送邮件
【发布时间】:2015-08-04 13:14:00
【问题描述】:

尝试在编码中有所防御,并且我正在尝试发送邮件,前提是与 SMTP 服务器的连接成功。目前,如果连接不成功,我会收到warning

如果发送的邮件是truefalse,我仍然可以捕捉到,但我想知道这样做的正确方法是什么,所以我不会发出警告。

当前代码:

    $this->email->message($content);
    if ($this->email->send()) {
    return true; }
    else{
        return false;
    }

我正在努力实现的目标,所以我不会发出警告。

if fsockopen connection successful {
        if ($this->email->send()) {
        return true; }
        else{
            return false;
        }
}

fsockopen 无法连接时,我现在收到警告。

Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (php_network_getaddresses: getaddrinfo failed: No such host is known. )

虽然它可以工作,而且我可以隐藏所有错误/警告,但我想要正确的方法:)

【问题讨论】:

    标签: php codeigniter smtp fsockopen


    【解决方案1】:

    在最近的版本中,PHPMailer 不使用fsockopen(它使用stream_socket_client),它会捕获并报告连接错误。我怀疑您使用的是旧版本,所以get the latest,并将您的代码基于它提供的示例。

    【讨论】:

    • 对不起,那个标签是偶然的。我正在使用 Codeigniter 自己的邮件助手类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多