【问题标题】:can not send email by codeigniter [duplicate]无法通过codeigniter发送电子邮件[重复]
【发布时间】:2018-10-12 06:32:45
【问题描述】:

我使用下面的代码来发送电子邮件,但在本地和实时服务器中不起作用?

//this function sends a confirmation email to the user while registration
public function send_email($email,$message,$subject) {
     // configuration
    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'example@gmail.com', 
      'smtp_pass' => 'password', 
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
    );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->from('example@gmail.com');
    $this->email->to($email);
    $this->email->subject($subject);
    $this->email->message($message);
    $result = $this->email->send();
    $this->email->clear();
    return ($result);
}

【问题讨论】:

  • 尝试使用不同的端口,例如 587。请将输出粘贴到此处。
  • 不!它在端口 587 上不起作用
  • 我的方法返回“1”,在我看来它发送了,但是当我在我的计算机中结帐时输出电子邮件文件夹是空的
  • 请检查电子邮件是否被发送到垃圾邮件文件夹。
  • 不!它们不在垃圾邮件文件夹中,我的配置设置是否正确?

标签: php codeigniter email backend mail-server


【解决方案1】:

试试这些设置:

// The mail sending protocol.
$config['protocol'] = 'smtp';
// SMTP Server Address for Gmail.
$config['smtp_host'] = ssl://smtp.googlemail.com
// SMTP Port - the port that you is required
$config['smtp_port'] = 465;
// SMTP Username like. (abc@gmail.com)
$config['smtp_user'] = $sender_email;
// SMTP Password like (abc***##)
$config['smtp_pass'] = $user_password;
// Load email library and passing configured values to email library
$this->load->library('email', $config);
// Sender email address
$this->email->from($sender_email, $username);
// Receiver email address.for single email
$this->email->to($receiver_email);
//send multiple email
$this->email->to(abc@gmail.com,xyz@gmail.com,jkl@gmail.com);
// Subject of email
$this->email->subject($subject);
// Message in email
$this->email->message($message);
// It returns boolean TRUE or FALSE based on success or failure
$this->email->send(); 

【讨论】:

  • 不,有了以上所有答案,我无法在我的实时服务器上发送任何电子邮件
【解决方案2】:

您使用的是 gmail smtp 对吗?我以前也遇到过这样的问题。然后我在我的谷歌帐户上激活允许不太安全的应用程序

然后就可以了

【讨论】:

    猜你喜欢
    • 2012-12-10
    • 1970-01-01
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-06
    • 1970-01-01
    • 2013-02-21
    相关资源
    最近更新 更多