Codeigniter SMTP邮件配置

时间:2015-10-21 16:44:55

标签: php codeigniter email smtp

我正在尝试通过SMTP发送邮件,但CI可能无法识别config详细信息,因此它会尝试连接我自己的服务器SMTP

这是我发送邮件的代码:

    $config =   array
    (
    'protocol'      =>  'smtp',
    'smtp_host'     =>  'in-v3.mailjet.com',
    'smtp_port'     =>  '587',
    'smtp_user'     =>  'myusername',
    'smtp_pass'     =>  'mypassword',
    'mailtype'      =>  'html',
    'newline'       =>  '\r\n',
    'charset'       =>  'utf-8',
    'validation'    =>  TRUE
    );

    $this->load->library('email', $config);
    $this -> email -> from('my@mailaddress.com');
    $this -> email -> to('to@mailaddress.com');
    $this -> email -> subject('mySubject');
    $this -> email -> message('myMessage');
    $this -> email -> send();

    echo $this -> email -> print_debugger();

这是我的输出:

220-server.myserver.com ESMTP Exim 4.86 #2 Wed, 21 Oct 2015 19:38:24 +0300 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. 
hello: 250-server.myserver.com Hello li14.members.linode.com [my.ip.address.here]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
535 Incorrect authentication data 

它给出535,这是正常的'因为它必须连接mailjet的服务器,而不是我的。我尝试了不同的配置初始化方法,但结果是一样的。

提前感谢。

2 个答案:

答案 0 :(得分:0)

加载库后初始化配置。试试这个。

$config = array( 
    'protocol' => 'smtp', 
    'smtp_host' => 'mail.google.com', 
    //'smtp_port' => '465', 
    'smtp_timeout' => '7', 
    'smtp_user' => 'info@gmail.com', 
    'smtp_pass' => 'password', 
    'charset' => 'utf-8', 
    'newline' => "rn", 
    'mailtype' => 'html', // or html 
    'wordwrap' => FALSE, 
    'validation' => TRUE // bool whether to validate email or not 
); 

$this->load->library('email'); 
$this->email->initialize($config); 
$this->email->set_newline("rn"); 
$this->email->from($email, 'Subject'); 
$this->email->to('nam@gmail.com,nam@gmail.com,nam@gmail.com'); 
$this->email->subject('Contact us form by: ' . $name); 
$this->email->message($message . '<br>website:' . $website); 
$this->email->send(); 

//echo $this->email->print_debugger(); `enter code here` 

答案 1 :(得分:0)

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


$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '******',
'smtp_pass' => '******',
'mailtype'  => 'html', 
'charset' => 'utf-8',
'wordwrap' => TRUE
 );

       $this->load->library('email', $config);
       $this->email->set_newline("\r\n");
        $this->email->from('******', "Name");
        $this->email->to($email);
        $this->email->subject("success");
        $message = "<p>This email has been sent success</p>";
        $this->email->message($message);
        $this->email->send();