无法在Codeigniter中发送html电子邮件

时间:2015-11-10 09:45:20

标签: php codeigniter email

您好我需要帮助我一直尽力发送html电子邮件,但它不起作用我只是收到电子邮件尚未发送的警报。 在图书馆中> email.php文件我没有更改任何刚刚离开的默认值请帮助,因为我一直试图解决这个问题,因为两周前请帮忙!

        $name = $this->input->post('name');

        $email = $this->input->post('email');

        $comment = $this->input->post('message');

        $config['mailtype'] = 'html';

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

        $message =  "<html>";

        $message .= "<style type='text/css'> body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 13px;}</style>";

        $message .=  "<body>";

        $message .= "<table width='650' border='1' cellspacing='0' cellpadding='6'> ";

        $message .= "<tr>";

        $message .= "<td colspan='2' bgcolor='#6495ed' style='font-weight: bold;'>CONTACT DETAILS</td>";

        $message .= "</tr>";

        $message .= "<tr>";

        $message .= "<td width='237'>Client Name:</td>"."<td width='393'>".$name."</td>";


        $message .= "</tr>";

        $message .=  "<tr>";

        $message .=  "<td>Message:</td>"."<td>".$comment."</td>";

        $message .= "</table><br><br>";

        $message .= "</body>";

        $message .= "</html>";



        $this->email->from($email,$name);

        $this->email->to('fredma@gmail.com','nfy@layeaketz.com');

        $this->email->subject('New Contact Email from Client');

        $this->email->message($message);

        $this->email->send();

        if($this->email->send()== TRUE){
            echo'message sent';
        }else{
            echo'message not sent';

        }

2 个答案:

答案 0 :(得分:1)

因为您在代码中发送了两次电子邮件

$this->email->send();// first time

if($this->email->send()== TRUE){ //and second time here

$this->email->send()之后,每件事情都清楚了。只需使用

$this->email->message($message);
        if($this->email->send()== TRUE){
            echo'message sent';
        }else{
            echo'message not sent';
        }

答案 1 :(得分:0)

使用googlemail smtp发送邮件

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

$config = Array(   
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'abc@gmail.com', // change it to yours
        'smtp_pass' => '*******', // change it to yours
        'mailtype' => 'html', // text
        'charset' => 'iso-8859-1',
        'newline' => '\r\n',
        'wordwrap' => TRUE
    );

    $this->email->initialize($config);
    $this->email->from('abc@gmail.com'); 
    $this->email->to('test@gmail.com');

    $this->email->subject('Test mail');
    $this->email->message('Test HTML Data');
    if($this->email->send())
    {

        echo "Mail sent";
    }
    else
    {
        show_error($this->email->print_debugger());
    }