簡體   English   中英

在codeigniter中發送電子郵件問題

[英]sending email issue in codeigniter

我在codeigniter中有配置電子郵件

    'protocol' => 'smtp',
                    'smtp_host' => 'ssl://smtp.gmail.com',
                    'smtp_port' => '465',
                    'smtp_user' => '-----',
                    'smtp_pass' => '-----',
                    'mailtype' => 'html',
                    'charset' => 'utf-8'

$this->load->library('email', $this->session->userdata('config'));
            $this->email->from('new@gmail.com', 'Rtlx Team');
            $this->email->to($email);
            $message = "Dear ";
            $this->email->subject('Rtlx Team - Account Verification');
            $this->email->message($message);
            $this->email->send();
            $this->email->clear();

但是它顯示以下錯誤:

消息:mail()[function.mail]:無法通過“ localhost”端口465連接到郵件服務器,無法驗證php.ini中的“ SMTP”和“ smtp_port”設置或使用ini_set()

消息:mail()期望參數1為字符串,給定數組

無法使用PHP mail()發送電子郵件。 您的服務器可能未配置為使用此方法發送郵件。

您錯誤地將電子郵件庫加載為$this->load->library('email',$this->session->userdata('config'));

因此將其加載為$this->load->library('email'); 並將其初始化為$this->email->initialize($this->session->userdata('config'));

在下面的示例中,我采用了$config數組,但是您也可以像使用過的那樣在會話中進行自己的配置。 但是將所有選項設置為我在$config設置的選項,可以在會話的變量中設置它。

完整代碼如下:

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'your@mail.com', // change it to yours
    'smtp_pass' => 'yourpassword', // change it to yours
    'mailtype' => 'html',// it can be text or html
    'wordwrap' => TRUE,
    'newline' => "\r\n",
    'charset' => 'utf-8',
    );
    $this->load->library('email');
    $this->email->initialize($config);
    $this->email->from('your@mail.com',"Rtlx Team");
    $this->email->to('receiver@mail.com');
    $this->email->subject('Subject');
    $this->email->message('Sample message');
    if (!$this->email->send()) 
    {
        show_error($this->email->print_debugger()); 
    }
    else 
    {
        echo 'Your e-mail has been sent!';
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM