Php CodeIgniter电子邮件
我正在尝试使用codeigniter发送电子邮件。我是否可以在任何电子邮件中发送消息,例如gmail、yahoo或outlook.com?这就是我到目前为止所做的:Php CodeIgniter电子邮件,php,codeigniter,email,Php,Codeigniter,Email,我正在尝试使用codeigniter发送电子邮件。我是否可以在任何电子邮件中发送消息,例如gmail、yahoo或outlook.com?这就是我到目前为止所做的: public function sendmail() { $config['protocol'] = 'sendmail'; $config['mailpath'] = '/usr/sbin/sendmail'; $config['charset'] = 'iso-8859-1'; $config['
public function sendmail()
{
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->load->library('email',$config); // load email library
$this->email->set_newline ("\r\n");
$this->email->from('user@gmail.com', 'sender name');
$this->email->to('test@gmail.com');
$this->email->subject('Your Subject');
$this->email->message('ed wow sir');
if ($this->email->send())
echo "nasend na!";
else
echo $this->email->print_debugger();
}
它显示错误:
退出状态代码:1无法打开Sendmail的套接字。请查收
设置。无法使用PHP Sendmail发送电子邮件。您的服务器可能会
无法配置为使用此方法发送邮件
请与您的主机提供商联系以发送邮件。您可以使用邮件功能检查邮件是否被触发 在Codeigniter中,尝试使用smtp协议并使用gmail帐户进行测试,而不是发送邮件。我正在使用此代码: 示例代码是:
$config = Array(
'protocol' => 'smtp',
'smtp_crypto' => 'tls',
'smtp_host' => 'xxx',
'smtp_port' => 587,
'smtp_user' => 'xxx',
'smtp_pass' => 'xx',
'smtp_timeout' => '5',
'smtp_auth' => true,
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE,
'validate' => TRUE,
'priority' => 1,
'crlf' => "\r\n",
'newline' => "\r\n",
'bcc_batch_mode' => FALSE,
'bcc_batch_size' => 200
);
$this->load->library('email', $config);
$this->email->clear();
$this->email->from($from, $fromname);
$this->email->to($to); $this->email->set_mailtype("html");
$this->email->subject($subject);
$this->email->message($body);
if (!$this->email->send())
show_error($this->email->print_debugger());
else
echo 'Your e-mail has been sent!';
如果您使用的是localhost,您可能还需要在那里设置sendmail配置 XAMPP和WAMP的Sendmail后端设置 当你需要用谷歌发送邮件时
$mail_config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '********',
'smtp_pass' => '********',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $mail_config);
$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
if ($this->email->send() == TRUE) {
// Redirect to a success page or load a view or some thing
redirect('success_page');
} else {
echo $this->email->print_debugger();
exit;
}
共点火器
雅虎
我已经尝试了smtp协议和gmail,它可以在本地主机上运行,但如果我想将它发送到yahoo或outlook,并在我的服务器上运行,但它不起作用,该怎么办(我想说的是使用你的任意gmail帐户作为smtp凭据,并尝试将电子邮件发送到yahoo或outlook,检查它是否正常工作。)not@karthi与其创建多个答案,不如单击答案下方的“编辑”按钮重新编辑一个答案。谢谢它的工作原理,但如果我想在我的服务器中安装它,该怎么办se gmail帐户作为smtp凭据?我应该在smtp用户和密码中输入什么?使用服务器中的默认sendmail,我还没有为您尝试过,我将尝试…并发布
'smtp_host' => 'ssl://smtp.mail.yahoo.com'