在php-codeigniter中发送电子邮件时出现未配置错误

时间:2017-12-27 07:05:37

标签: php codeigniter email

请参阅下面的电子邮件发送代码,并在发送电子邮件时显示以下错误..

  

无法使用PHP mail()发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。

我的控制器:

 $from_email= "******"; 
 $to_email = 'dummy@dummy.com';
 $subject='Password Reset Request';
 $htmlContent = '<p>'.$link.'</p>';
     $this->load->library('email'); 
     $config['mailtype'] = 'html';
     $this->email->initialize($config);
     $this->email->set_newline("\r\n"); 
     $this->email->from($from_email,'*****'); 
     $this->email->to($to_email);
     $this->email->subject($subject); 
     $this->email->message($htmlContent);           
     $this->email->send();

此条件显示上述错误。实际上,它最初在开发阶段工作正常,但现在它不是..在这个查询中可能出错... ...提前谢谢你..

2 个答案:

答案 0 :(得分:0)

您正在使用const tableData = [ { name: 'return', 2016: 4, 2015: 5, 2014: 6 }, { name: 'stddev', 2016: 4, 2015: 5, 2014: 6 }, { name: 'sharpe', 2016: 4, 2015: 5, 2014: 6 }, { name: 'maxddown', 2016: 4, 2015: 5, 2014: 6 } ] ,但您的代码没有实际的配置。根据您的错误无法使用PHP邮件发送电子邮件(),您的服务器可以通过 sendmail 运行。

Elevation & Shadows

Email Class in codeingiter

$this->email->initialize($config);

使用此服务器检查外发邮件

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

$this->email->initialize($config);

大多数服务器传出端口为25或587

答案 1 :(得分:0)

如果你在localhost代码工作,你在实时服务器? 如果您的网址是 siteurl.domain ,请尝试

    $from_email= "email@siteurl.domain";  //from email must be from same server url
    $to_email = 'dummy@dummy.com';
    $subject='Password Reset Request';
    $htmlContent = '<p>'.$link.'</p>';

    //{INCLUDE SMTP CONFIG HERE IF THIS NOT WORKiNG THIS METHOD}

    $config['mailtype']  = 'html';
    $config['charset']   = 'iso-8859-1';
    $config['wordwrap']  = TRUE;
    $config['newline']   = "\r\n"; //use double quotes
    $this->email->initialize($config);     
    $this->email->from('$from_email', 'sender name');   
    $this->email->to($to_email);
    $this->email->subject($subject);
    $this->email->message($htmlContent);
    $this->email->send();

否则尝试使用SMTP :),

     //SMTP CONFIG

     $config['protocol']  = 'smtp';
     $config['smtp_host'] = 'ssl://smtp.gmail.com'; //smtp host name
     $config['smtp_port'] = '465'; //smtp port number
     $config['smtp_user'] = 'ji******@gmail.com';
     $config['smtp_pass'] = '*******'; //$from_email password
     //Continue above code

我无法评论(抱歉):), 有时SMTP方法不能与Bluehost帐户一起使用:(