本文介绍了如何正确的方式使用codeigniter发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嘿,我试图发送电子邮件使用codeiginiter邮件类功能,但我发现smtp协议的麻烦。我使用gmail smtp协议。 我在本地机器运行。 我使用Xampp 1.7.4包,我尝试设置如下:Hey guy, I'm trying to send email using codeiginiter mail class function, but I found a trouble with smtp protocol. I using gmail smtp protocol. I running this in local machine.I'm using Xampp 1.7.4 package, andI have tried setting like below :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();}及以下错误显示在我的浏览器中:and below error was show in my browser :error!220 mx.google.com ESMTP b8sm581192pbj.46hello: 250-mx.google.com at your service, [118.96.231.25]250-SIZE 35882577250-8BITMIME250-STARTTLS250 ENHANCEDSTATUSCODESFailed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46from: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46to: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46data: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46502 5.5.1 Unrecognized command. b8sm581192pbj.46The following SMTP error was encountered: 502 5.5.1 Unrecognized command. b8sm581192pbj.46Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.User-Agent: CodeIgniterDate: Wed, 1 Jun 2011 09:27:21 +0700From: "Me" Return-Path: Reply-To: "Me" To: [email protected]: =?utf-8?Q?testing_my_mail_function_with_CodeIgniter?=X-Sender: [email protected]: CodeIgniterX-Priority: 3 (Normal)Message-ID: <[email protected]>Mime-Version: 1.0Content-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_4de5a38938733Content-Type: text/plain; charset=utf-8Content-Transfer-Encoding: 8bitthis is the content--B_ALT_4de5a38938733Content-Type: text/html; charset=utf-8Content-Transfer-Encoding: quoted-printable<html><body>this is the content</body></html>--B_ALT_4de5a38938733-- 推荐答案出于安全考虑,Google的电子邮件服务器需要SSL或TLS 为了发送邮件。它不使用标准的未加密端口25方法。For security reasons, Google's e-mail servers require SSL or TLS in order to send mail. It doesn't use the standard unencrypted port 25 method of doing it.你基本上有两个选择。 1)在自己的服务器上使用sendmail或邮件来传递邮件,或2)使用此处描述的方法使用SSL通过Google的服务器发送电子邮件。祝你好运,我希望这有助于。You basically have two choices. 1) Use sendmail or mail on your own server to deliver the messages, or 2) use the method described here to send e-mail via Google's servers using SSL. Good luck, and I hope it this helps. 这篇关于如何正确的方式使用codeigniter发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 17:52