我目前正在建立一个在线注册系统,其中一个模块是注册系统。
用户成功注册后,会将验证电子邮件发送到他/她的电子邮件地址。我按照我在网上阅读的每个教程,我仍然遇到同样的问题。
这是我到目前为止所得到的:
//this is what it looks like in my controller after validation of fields from registration
$this->load->library('email');
$this->email->set_newline("\r\n");
$this->email->from('my_personal_email@gmail.com', 'Mike Lee');
$this->email->to($email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
if($this->email->send()){
//this is to check if email is sent
redirect('site/registered');
}else{
//else error
show_error($this->email->print_debugger());
}
我的配置email.php:
class CI_Email {
var $useragent = "CodeIgniter";
var $mailpath = "/usr/sbin/sendmail"; // Sendmail path
var $protocol = "smtp"; // mail/sendmail/smtp
var $smtp_host = "https://smtp.googlemail.com"; // SMTP Server. Example: mail.earthlink.net
var $smtp_user = "my_personal_email@gmail.com"; // SMTP Username
var $smtp_pass = "my_personal_emailpassword"; // SMTP Password
var $smtp_port = "25"; // SMTP Port
var $smtp_timeout = 10; // SMTP Timeout in seconds
var $smtp_crypto = ""; // SMTP Encryption. Can be null, tls or ssl.
var $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off
var $wrapchars = "76"; // Number of characters to wrap at.
var $mailtype = "text"; // text/html Defines email formatting
var $charset = "utf-8"; // Default char set: iso-8859-1 or us-ascii
var $multipart = "mixed"; // "mixed" (in the body) or "related" (separate)
var $alt_message = ''; // Alternative message for HTML emails
var $validate = FALSE; // TRUE/FALSE. Enables email validation
var $priority = "3"; // Default priority (1 - 5)
var $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
var $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers,
// even on the receiving end think they need to muck with CRLFs, so using "\n", while
// distasteful, is the only thing that seems to work for all environments.
var $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo.
var $bcc_batch_mode = FALSE; // TRUE/FALSE Turns on/off Bcc batch feature
var $bcc_batch_size = 200; // If bcc_batch_mode = TRUE, sets max number of Bccs in each batch
var $_safe_mode = FALSE;
var $_subject = "";
var $_body = "";
var $_finalbody = "";
var $_alt_boundary = "";
var $_atc_boundary = "";
var $_header_str = "";
var $_smtp_connect = "";
var $_encoding = "8bit";
var $_IP = FALSE;
var $_smtp_auth = FALSE;
var $_replyto_flag = FALSE;
var $_debug_msg = array();
var $_recipients = array();
var $_cc_array = array();
var $_bcc_array = array();
var $_headers = array();
var $_attach_name = array();
var $_attach_type = array();
var $_attach_disp = array();
var $_protocols = array('mail', 'sendmail', 'smtp');
var $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix)
var $_bit_depths = array('7bit', '8bit');
var $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
这是错误:
/ * 遇到PHP错误
严重性:警告
消息:fsockopen()[function.fsockopen]:无法连接到ssl://smtp.googlemail.com:25(连接尝试失败,因为连接方在一段时间后没有正确响应,或已建立连接失败,因为连接的主机无法响应。)
文件名:libraries / Email.php
行号:1689 * /
我使用我的个人电子邮件帐户发送测试邮件。但我不知道这是否适用于Gmail。你能以某种方式启发我如何测试我的代码是否正常工作?或者是否有可用作我的测试服务器发送邮件的软件?
感谢。 :(
答案 0 :(得分:0)
从我看到的所有教程,以及我使用的所有应用程序中,我只使用了465作为我的端口来连接谷歌电子邮件。如果我错了但你正在编辑实际的库,还要纠正我?因为我在您粘贴的代码的顶部看到了类电子邮件。你应该做的是进入application / config目录,并创建一个名为email.php的php文件然后该文件的内容应该包括:(这是我的内容,你显然可以改变它)
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = '';
$config['smtp_pass'] = '';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 30;
$config['charset'] = 'utf-8';
$config['crlf'] = "\n";
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['priority'] = 1;
$config['validate'] = TRUE;
您的案例中的一些问题是您尝试通过未加密的端口发送加密的电子邮件(25)。 Based on this useful reading:
SMTP使用端口25,但SSL / TLS加密SMTP使用端口465
因此,您要使用的端口号和协议不一致。