2011-06-01 132 views
7

嘿傢伙,我試圖使用codeiginiter郵件類功能發送電子郵件,但我發現與smtp協議的麻煩。我使用Gmail的SMTP協議。 我在本地機器上運行這個。 我使用的XAMPP 1.7.4包,安迪已經嘗試設置如下圖所示:如何糾正使用codeigniter發送電子郵件的方式

function index() 
{ 

    $config['protocol'] = 'smtp'; // mail, sendmail, or smtp The mail sending protocol. 
    $config['smtp_host'] = 'smtp.gmail.com'; // SMTP Server Address. 
    $config['smtp_user'] = '[email protected]'; // SMTP Username. 
    $config['smtp_pass'] = '123'; // SMTP Password. 
    $config['smtp_port'] = '25'; // SMTP Port. 
    $config['smtp_timeout'] = '5'; // SMTP Timeout (in seconds). 
    $config['wordwrap'] = TRUE; // TRUE or FALSE (boolean) Enable word-wrap. 
    $config['wrapchars'] = 76; // Character count to wrap at. 
    $config['mailtype'] = 'html'; // text or html Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work. 
    $config['charset'] = 'utf-8'; // Character set (utf-8, iso-8859-1, etc.). 
    $config['validate'] = FALSE; // TRUE or FALSE (boolean) Whether to validate the email address. 
    $config['priority'] = 3; // 1, 2, 3, 4, 5 Email Priority. 1 = highest. 5 = lowest. 3 = normal. 
    $config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822). 
    $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822). 
    $config['bcc_batch_mode'] = FALSE; // TRUE or FALSE (boolean) Enable BCC Batch Mode. 
    $config['bcc_batch_size'] = 200; // Number of emails in each BCC batch. 

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


    $this->email->from('[email protected]', 'Me'); 
    $this->email->reply_to('[email protected]', 'Me'); 
    $this->email->to('[email protected]'); 
    $this->email->subject('testing my mail function with CodeIgniter'); 
    $this->email->message('<html><body>this is the content</body></html>'); 

    if (! $this->email->send()){ 
     echo 'error! <br />'; 
     // Generate error 
    } 
    echo $this->email->print_debugger(); 

} 

及以下的錯誤是顯示在瀏覽器中:

error! 
220 mx.google.com ESMTP b8sm581192pbj.46 

hello: 250-mx.google.com at your service, [118.96.231.25] 
250-SIZE 35882577 
250-8BITMIME 
250-STARTTLS 
250 ENHANCEDSTATUSCODES 

Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

from: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

to: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

data: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 
502 5.5.1 Unrecognized command. b8sm581192pbj.46 
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. b8sm581192pbj.46 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. 

User-Agent: CodeIgniter 
Date: Wed, 1 Jun 2011 09:27:21 +0700 
From: "Me" 
Return-Path: 
Reply-To: "Me" 
To: [email protected] 
Subject: =?utf-8?Q?testing_my_mail_function_with_CodeIgniter?= 
X-Sender: [email protected] 
X-Mailer: CodeIgniter 
X-Priority: 3 (Normal) 
Message-ID: <[email protected]> 
Mime-Version: 1.0 


Content-Type: multipart/alternative; boundary="B_ALT_4de5a38938733" 

This is a multi-part message in MIME format. 
Your email application may not support this format. 

--B_ALT_4de5a38938733 
Content-Type: text/plain; charset=utf-8 
Content-Transfer-Encoding: 8bit 

this is the content 


--B_ALT_4de5a38938733 
Content-Type: text/html; charset=utf-8 
Content-Transfer-Encoding: quoted-printable 

<html><body>this is the content</body></html> 

--B_ALT_4de5a38938733-- 

回答

3

您正嘗試通過Gmail發送出站郵件在標準SMTP端口25上。Gmail不接受該端口(或任何端口)上的未加密連接。您必須通過SSL使用端口465

你必須改變你的$config['smtp_port']465和你$config['smtp_host']'ssl://smtp.googlemail.com'

More info here

+1

你的第二個數組密鑰應該是smtp_host – willoller 2011-11-19 00:15:44

9

出於安全原因,谷歌的電子郵件服務器require SSL or TLS以發送郵件。它不使用標準的未加密端口25的方法。

你基本上有兩種選擇。 1)在自己的服務器上使用sendmail或郵件發送郵件,或者2)使用方法described here通過使用SSL的Google服務器發送電子郵件。祝你好運,我希望這有助於。

+0

如果你選擇在XAMPP上使用sendmail,那麼記得省略smtp主機的協議部分,這樣你就可以用smtp_server = smtp.googlemail.com – KalenGi 2011-12-21 06:23:57

3

你甚至可以使用端口587:

$config['smtp_port'] = '587'; 

和SMTP主機爲:

$config['smtp_host'] = 'ssl://smtp.gmail.com'; 
+0

JUST LEADS TO' fsockopen():SSL:現有連接被遠程主機強制關閉 – SpYk3HH 2016-08-08 22:58:21

-1

1)您的SMTP端口必須465

2)你的smtp主機必須是ssl://smtp.gmail.com

$config['smtp_host'] = 'ssl://smtp.gmail.com'; 

而且一定要使用465端口(這是谷歌的SMTP端口):

$config['smtp_host'] = 'ssl://smtp.gmail.com'; // SMTP Server Address. 

$config['smtp_port'] = '465'; // SMTP Port. 
1

我通過包括smtp_hostSSL前綴離開這種方式解決了這個問題

$config['smtp_port'] = '465'; 

否則,默認情況下谷歌阻止'低安全性conections',所以你c輸入您的谷歌帳戶並配置此選項。

Allow less secure apps to access accounts

激活此選項,然後再試一次。希望這可以幫到你!。

相關問題