[英]how to send email in codeigniter on localhost
你好,我必须在本地主机上发送电子邮件,以下是我的配置文件
$config['useragent'] = "CodeIgniter";
$config['mailpath'] = "/usr/sbin/sendmail -t -i";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'xyz.com'; //change this
$config['smtp_port'] = '465';
$config['smtp_user'] = 'xyz.com'; //change this
$config['smtp_pass'] = '######'; //change this
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
我为电子邮件发送创建了以下代码
if(count($result) > 0 || $result != NULL){
$password=$result['password'];
$this->load->library('email');
$from='chirag@site.com';
$to=$email;
$subject='forget password';
$this->email->from($from);
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($password);
if($this->email->send()){
$this->session->set_flashdata('email','We sent your password to your Email...!');
redirect('login');
}
else{
echo $this->email->print_debugger();
}
}
但是当我发送电子邮件时出现以下错误
The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
那么有什么问题呢? 请帮我解决
我得到了答案,配置中缺少 ssl:// 但在编写以下内容后
$config['smtp_host'] = 'ssl://xyz.com';
邮件发送成功...
首先确保您已经为发送电子邮件完成了正确的本地主机配置。 然后在您的控制器中,您通过设置适当的凭据和端口号来加载电子邮件库。 像这样:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'your_gmail_name@gmail.com',
'smtp_pass' => 'your_pass',
//'mailtype' => 'html',
// 'charset' => 'iso-8859-1',
// 'wordwrap' => TRUE
);
$this->load->library('email', $config);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.