无法发送没有" From"标题---- codeigniter 3

时间:2015-05-05 08:22:41

标签: codeigniter sendmail

我正在使用live server并使用codeigniter 3。

我无法收到任何邮件。

当我运行此代码时,我收到以下错误

无法发送没有"来自"标题

        $config = array();
        $config['useragent']           = "CodeIgniter";
        $config['mailpath']            = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
        $config['protocol']            = "smtp";
        $config['smtp_host']           = "localhost";
        $config['smtp_port']           = "25";
        $config['mailtype'] = 'html';
        $config['charset']  = 'utf-8';
        $config['newline']  = "\r\n";
        $config['wordwrap'] = TRUE;

        $this->load->library('email');

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

        $this->email->from('admin@lucky.com','admin');
        $this->email->to('my@gmail.com');
        $this->email->cc('my@gmail.com'); 
        $this->email->subject('Registration Verification');
        $msg = "Thanks for signing up";
        $this->email->message($msg);   
        //$this->email->send();
         if (!$this->email->send())
        {    
        echo $this->email->print_debugger();
        } 
         else{echo 'success';}

3 个答案:

答案 0 :(得分:2)

这里错了

$this->email->send();
if (!$this->email->send())
{    
echo $this->email->print_debugger();                
} 

在您的代码中,您已经使用了$ this-> email-> send(),然后在if语句中再次使用$ this-> email-> send()。发送电子邮件后,图书馆会清除所有内容。因此,如果您想在出现错误时执行某些操作,则不要执行相同的方法两次:

尝试

// $this->email->send(); don't do this and then the same thing!

if (!$this->email->send())
{    
echo $this->email->print_debugger();

} 

阅读CI email

答案 1 :(得分:1)

尝试普通邮件发送功能

HTML表格式

<?php
if(isset($_POST['submit']))
{
    $to = 'mail@mail.com';//your mail
    $subject = 'Subject is here';
    $message = '<html><body>';
    $message .= '<table rules="all" style="border: 1px solid #000000" cellpadding="10">';
    $message .= '<caption style="font-size: 18pt"><strong>Feedback from Customers (Testimonial)</strong></caption>';
    $message .= "<tr><td width='25'><strong>Name</strong> </td><td width='60'>".strip_tags($_POST['name'])."</td></tr>";
    $message .= "<tr><td><strong>Email</strong> </td><td>" .strip_tags($_POST['mail']) . "</td></tr>";
    $message .= "<tr><td><strong>Country</strong> </td><td>" .strip_tags($_POST['country']) . "</td></tr>";
    $message .= "<tr><td><strong>Message</strong> </td><td>" . strip_tags($_POST['message']). "</td></tr>";
    $message .= "<tr style='background: #eee;'><td><strong>Comment Activate Link</strong></td><td>" . $active. "</td></tr>";
    $message .= "</table>";
    $message .= "</body></html>";

    $headers = "Cc: info@mail.com"; // can use $headers = "From:
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

     mail($to, $subject, $message, $headers);
 }
?>

或者

搁浅邮件格式

<?php
if(isset($_POST['submit']))
{
    $to = 'mail@mail.com';//your mail
    $subject = 'Subject is here';
    $message = 'text'; //simple para


    $headers = "Cc: info@mail.com";// can use $headers = "From:


     mail($to, $subject, $message, $headers);
 }
 ?>

答案 2 :(得分:0)

使用三元运算符如下

void AddItem(info& item)
相关问题