简单的邮件功能在编码点火器中不起作用


simple mail function not working in codeigniter

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

检查您的 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实用程序。

    $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();

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

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

如果这只是为了测试,我建议您使用Mailtrap SMTP它是免费的,仅用于测试电子邮件。

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