2015-10-21 51 views
0

我试图通过SMTP发送邮件,但可能CI没有识别config的详细信息,因此它会尝试连接我自己的服务器的SMTPCodeigniter 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('[email protected]'); 
    $this -> email -> to('[email protected]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的服务器,而不是我的。我尝试了不同的配置初始化方法,但结果相同。

提前致谢。

+0

此消息,请重置您的用户名/密码,您的SMTP服务器 – Linus

+0

。请仔细阅读,当然它给这个错误,因为它试图连接错误的服务器,这是我的问题。 –

回答

0

加载库后初始化配置。尝试这个。如果您的密码或用户名不被发送服务器接受出现

$config = array( 
    'protocol' => 'smtp', 
    'smtp_host' => 'mail.google.com', 
    //'smtp_port' => '465', 
    'smtp_timeout' => '7', 
    'smtp_user' => '[email protected]', 
    '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('[email protected],[email protected],[email protected]'); 
$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` 
+0

我已经试过这个,结果相同。 –

+0

你试过这个吗? '$ this-> email-> initialize($ config);' – Suraj

+0

当然。相同。 –

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();