【问题标题】:connection time out issue when sending email for codeigniter为 codeigniter 发送电子邮件时出现连接超时问题
【发布时间】:2014-03-08 16:48:36
【问题描述】:

向 codeigniter 发送电子邮件时遇到问题。

    $config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'email@gmail.com',
'smtp_pass' => 'xxxxx',
'mailtype'  => 'html', 
 'charset'   => 'iso-8859-1'

);

$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->to($user['company_email']);
$this->email->from('noreply@email.com', 'COMPANY');   
$this->email->subject('Password reset');
$this->email->message('You have requested a code. Here is your code: '. $reset['return_pass']);  
    $this->email->send();

有时,我可以毫无问题地发送电子邮件,但如果我多次使用它或多个用户使用此发送电子邮件(忘记密码),googlemail 无法连接到 ssl://smtp.googlemail.com: 465(连接超时),用户收不到邮件。我该如何解决这个问题?这是 googlemail 的安全问题吗?

【问题讨论】:

  • 我尝试了可能的重复,但仍然有错误。我的代码在发送单个电子邮件时有效。但是当我多次发送它进行测试时,我收到了错误。请检查我的问题。谢谢
  • @SetSailMedia - 我的问题是我的代码正在运行,但是当多个用户同时发送时,googlemail 会阻止它并且会出错
  • 错误是什么?问题是 Google 对出站 SMTP 连接有速率限制。因此,如果您同时进行多次尝试,Google 将阻止以后的尝试。您几乎需要将电子邮件排队并每隔 __ 秒或分钟发送一次。
  • @SetSailMedia 我的错误是:消息:fsockopen() [function.fsockopen]:无法连接到 ssl://smtp.gmail.com:465(连接超时)和用户不会收到任何电子邮件。有没有其他方法可以用作主机?
  • 您使用的电子邮件库是什么?你可以试试phpmailer

标签: php codeigniter email


【解决方案1】:

我遇到了类似的问题。首先,检查垃圾邮件,因为当我测试我的邮件时,Google 认为它们是垃圾邮件并开始将它们分类。

我发现使用这种协议向多个用户发送邮件非常不可靠,所以我只是运行了一个循环来发送邮件:

function sendEmail($user){
     $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => 465,
        'smtp_user' => 'email@gmail.com',
        'smtp_pass' => 'xxxxx',
        'mailtype'  => 'html', 
        'charset'   => 'iso-8859-1'
     );

    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->to($user);
    $this->email->from('noreply@email.com', 'COMPANY');   
    $this->email->subject('Password reset');
    $this->email->message('You have requested a code. Here is your code: '.
    $reset['return_pass']);  
    $this->email->send();
}


$users = array("person1@test.com", "person2@test.com");

foreach($users as $user){
    sendMail($user);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-29
    • 2011-10-28
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 2015-09-15
    相关资源
    最近更新 更多