我在Codeigniter控制器中发送了这个邮件代码。
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$this->load->library('email');
$this->email->initialize($config);
$this->email->from('mymail@yahoo.com', 'myname');
$this->email->to('testingmail@gmail.com');
$this->email->subject('Email Test');
$this->email->message('Testing .');
$this->email->send();
echo $this->email->print_debugger();
但它显示unable to send email using PHP mail()
。请帮我解决这个问题。
答案 0 :(得分:1)
检查您的PHP配置(php.ini)是否有正确的mail
值:
[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25
; For Win32 only.
;sendmail_from = me@example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail
根据您的操作系统评论/取消注释行。
您还可能需要安装sendmail
实用程序。
答案 1 :(得分:0)
$this->load->library('email');
$this->email->from('');
$this->email->to('');
$this->email->subject('subject');
$this->email->set_mailtype('html');
$datas['title'] = "title";
$datas['footer'] = '© '.date("Y").' www.aaa.com All rights reserved';
$con1 = '
<p style="Calibri, Verdana, Ariel, sans-serif; font-size:11px; color:#666666"> Hello , </p>
<p class="commen_text" style="font:Calibri, Verdana, Ariel, sans-serif; font-size:11px;font-weight:normal; color:#666666;text-align:justify;">content here.</p>
';
$con2 ='
<p class="commen_text" style="font:Calibri, Verdana, Ariel, sans-serif; font-weight:normal;font-size:11px;color:#666666;text-align:justify;">Please download the attachement. </p>
<p style="border-bottom: 1px solid rgb(235, 235, 235); font-size: 1px; margin-top: 0px;"> </p>
';
$this->email->attach('/path/of/the/file');
$datas['content']=$con1.$con2;
$msg = $this->load->view('include/email_template', $datas, TRUE); // create base html file and echo title, content and footer there
$this->email->message($msg);
$this->email->send();
答案 2 :(得分:0)
我不知道为什么你仍然想使用邮件功能而不是使用电子邮件类 https://ellislab.com/codeigniter/user-guide/libraries/email.html
您可以使用用户gmail smtp设置发送电子邮件。这更加健壮。
如果仅用于测试,我建议您免费使用Mailtrap SMTP并仅用于测试电子邮件。
如果你想要一个lib,你可以使用它:https://github.com/jaiwalker/mailtrap