[英]sending email issue in codeigniter
I have config email in codeigniter 我在codeigniter中有配置电子邮件
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => '465',
'smtp_user' => '-----',
'smtp_pass' => '-----',
'mailtype' => 'html',
'charset' => 'utf-8'
$this->load->library('email', $this->session->userdata('config'));
$this->email->from('new@gmail.com', 'Rtlx Team');
$this->email->to($email);
$message = "Dear ";
$this->email->subject('Rtlx Team - Account Verification');
$this->email->message($message);
$this->email->send();
$this->email->clear();
But it shows following errors: 但是它显示以下错误:
Message: mail() [function.mail]: Failed to connect to mail server at "localhost" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() 消息:mail()[function.mail]:无法通过“ localhost”端口465连接到邮件服务器,无法验证php.ini中的“ SMTP”和“ smtp_port”设置或使用ini_set()
Message: mail() expects parameter 1 to be string, array given 消息:mail()期望参数1为字符串,给定数组
Unable to send email using PHP mail(). 无法使用PHP mail()发送电子邮件。 Your server might not be configured to send mail using this method. 您的服务器可能未配置为使用此方法发送邮件。
通过链接http://ellislab.com/codeigniter/user-guide/libraries/email.html和您的smtp设置...
You are loading email library incorrectly as $this->load->library('email',$this->session->userdata('config'));
您错误地将电子邮件库加载为$this->load->library('email',$this->session->userdata('config'));
. 。
so load it as $this->load->library('email');
因此将其加载为$this->load->library('email');
and initialize it as $this->email->initialize($this->session->userdata('config'));
并将其初始化为$this->email->initialize($this->session->userdata('config'));
in below example i have taken $config
array but you can take your own configuration in session also as in question you have used. 在下面的示例中,我采用了$config
数组,但是您也可以像使用过的那样在会话中进行自己的配置。 but set all option as i have set in $config
you can set it in session's variable. 但是将所有选项设置为我在$config
设置的选项,可以在会话的变量中设置它。
full code below: 完整代码如下:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'your@mail.com', // change it to yours
'smtp_pass' => 'yourpassword', // change it to yours
'mailtype' => 'html',// it can be text or html
'wordwrap' => TRUE,
'newline' => "\r\n",
'charset' => 'utf-8',
);
$this->load->library('email');
$this->email->initialize($config);
$this->email->from('your@mail.com',"Rtlx Team");
$this->email->to('receiver@mail.com');
$this->email->subject('Subject');
$this->email->message('Sample message');
if (!$this->email->send())
{
show_error($this->email->print_debugger());
}
else
{
echo 'Your e-mail has been sent!';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.