【问题标题】:How can i get gmail smtp server working again?我怎样才能让 gmail smtp 服务器再次工作?
【发布时间】:2020-01-12 18:29:09
【问题描述】:

大家好,我在使用 gmails SMTP 服务器发送邮件时遇到问题。它最近工作得很好,我的项目离开了两天,当我回来时它停止了。请帮忙。我尝试更改 php.ini 中的 smtp 端口和所有必要的东西,但没有。我正在尝试添加新用户,但使用 google smtp 服务器向新用户发送验证电子邮件。这是我的“加入控制器”代码。

function _email($email, $activation_code)
{
    $config = [
        'mailtype'      => 'html',
        'charset'       => 'utf-8',
        'protocol'      => 'smtp',
        'smtp_host'     => 'smtp.gmail.com',
        'smtp_user'     => 'someone@gmail.com', // gmail address
        'smtp_pass'     => 'xxxxxxx', // gmail password
        'smtp_crypto'   => 'ssl',
        'smtp_port'     => 465,
        'crlf'          => "\r\n",
        'newline'       => "\r\n"
    ];
    $this->load->library('email', $config);
    $this->email->from('someone@gmail.com', 'username');

    $this->email->to($email);
    $this->email->subject('[Confirmation Email]');

    $html = '
        <div style="margin-bottom: 20px; font-weight: bold;">Hello There,</div>

        <div>Thank you for using and for join.</div>
        <div style="margin-bottom: 10px;">To activate your account, please click this link and we will redirect you to login page: <a href="'.base_url('activate?code='.$kode_aktifasi.'&email='.$email).'">Confirm my email address</a>.
        </div>
        <div>If that link cannot working you can access this URL from your browser</div>
        <div><a href="'.base_url('activate?code='.$kode_aktifasi.'&email='.$email).'">'.base_url('activate?code='.$kode_aktifasi.'&email='.$email).'</a></div>

        <div style="margin-bottom: 20px; margin-top: 10px;">If you have a question reply this email and we will contact you as soon as possible, thank you!</div>
    ';

    $this->email->message($html);
    return $this->email->send();
}

}

然后这是我得到的错误: PHP Error

【问题讨论】:

  • load-&gt;library 是做什么的?请添加功能。来自错误smtp_host is not being used
  • 你能发布你得到的错误的确切输出,你在哪一行得到这些?
  • 我投票决定将此问题作为离题结束,因为它与代码无关。 it is the avast antivirus which was blocking my port

标签: php smtp gmail


【解决方案1】:

查看代码我猜你正在使用 CodeIgniter?第 3 版?

如果是这样,您需要使用您的设置初始化库。在加载库的行之后,尝试添加:

$this-&gt;email-&gt;initialize($config);

请务必使用 Gmail 支持的设置:

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'you@gmail.com',
    'smtp_pass' => 'xxx',
);

此外,由于这不是 OAUTH 或 2FA 授权流程,您可能需要enable less secure apps 才能连接到 gmail 帐户。

(该链接用于调整您个人 Gmail 的设置。如果您使用 Gmail 企业帐户,您的系统管理员可能需要为您调整此设置。)

【讨论】:

  • 好的,谢谢,所以我添加了该行并且该错误消失了,但是,弹出了一个新错误。以下是消息:错误消息 1:消息:fsockopen():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:1416F086:SSL 例程:tls_process_server_certificate:证书验证失败文件名:libraries/Email.php 行号:2061
  • 经过一番研究,伙计们,我发现是avast杀毒软件阻塞了我的端口。所以禁用它后,我的网站运行良好。谢谢你的支持。你们真棒! ;-)
  • @Agent96 在这种情况下请删除问题,因为问题与编程无关
猜你喜欢
  • 1970-01-01
  • 2012-07-29
  • 2021-05-29
  • 1970-01-01
  • 2021-01-22
  • 2011-04-26
  • 1970-01-01
  • 1970-01-01
  • 2013-07-22
相关资源
最近更新 更多