无法发送没有"From"标头----代码点火器 3 的邮件



我在实时服务器上工作并使用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']  = "rn";
        $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';}

这是错误的

$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电子邮件

尝试普通邮件发送功能

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.0rn";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1rn";
     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);
 }
 ?>

使用三元运算符如下

($this->email->send())? $this->session->set_flashdata("email_sent","Email sent successfully."): 
$this->session->set_flashdata("email_sent","Email not sent, there was error"); 

最新更新