0

我在 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()。请帮我解决问题。

4

3 回答 3

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实用程序。

于 2013-11-07T07:16:41.587 回答
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.&nbsp;&nbsp;</p>
            <p style="border-bottom: 1px solid rgb(235, 235, 235); font-size: 1px; margin-top: 0px;">&nbsp;</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();
于 2014-06-16T04:38:29.050 回答
0

我不知道为什么你仍然想使用邮件功能而不是使用电子邮件类 https://ellislab.com/codeigniter/user-guide/libraries/email.html

您可以使用用户 gmail smtp 设置发送电子邮件。哪个更健壮。

如果这仅用于测试,我建议您免费使用 Mailtrap SMTP,并且仅用于测试电子邮件。

如果你想要一个库,你可以使用这个:https ://github.com/jaiwalker/mailtrap

于 2015-04-11T08:47:24.817 回答