首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用codeigniter正确发送电子邮件

如何使用codeigniter正确发送电子邮件
EN

Stack Overflow用户
提问于 2011-06-01 10:45:55
回答 5查看 32K关注 0票数 7

嘿,伙计,我正在尝试使用codeiginiter邮件类函数发送电子邮件,但我发现smtp协议有问题。我使用的是gmail smtp协议。我在本地机器上运行这个。我使用的是Xampp 1.7.4包,andI已经尝试过如下设置:

代码语言:javascript
运行
复制
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'] = 'me@gmail.com'; // 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('me@gmail.com', 'Me');
    $this->email->reply_to('me@gmail.com', 'Me');
    $this->email->to('you@yahoo.com');
    $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();

}

在我的浏览器中显示了下面的错误:

代码语言:javascript
运行
复制
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: you@yahoo.com
Subject: =?utf-8?Q?testing_my_mail_function_with_CodeIgniter?=
X-Sender: me@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4de5a38938720@gmail.com>
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--
EN

回答 5

Stack Overflow用户

发布于 2011-06-01 11:06:16

出于安全原因,谷歌的电子邮件服务器使用require SSL or TLS来发送邮件。它不使用标准的未加密端口25方法来完成此操作。

你基本上有两个选择。1)使用sendmail或您自己的服务器上的邮件来传递消息,或者2)使用described here方法通过谷歌的服务器发送电子邮件。祝你好运,我希望这对你有帮助。

票数 9
EN

Stack Overflow用户

发布于 2011-06-01 11:02:08

您正试图通过标准SMTP端口25上的Gmail发送出站邮件。Gmail不接受该端口(或任何端口)上的未加密连接。您必须使用SSL上的端口465

您必须将$config['smtp_port']更改为465,将$config['smtp_host']更改为'ssl://smtp.googlemail.com'

More info here

票数 3
EN

Stack Overflow用户

发布于 2012-10-12 20:46:09

您甚至可以使用端口587:

代码语言:javascript
运行
复制
$config['smtp_port'] = '587';

和smtp主机为:

代码语言:javascript
运行
复制
$config['smtp_host'] = 'ssl://smtp.gmail.com';
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6195709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档