PHP:电子邮件只适用于某些电子邮件客户端
我正在创建一个使用Codeigniter和Ion Auth Library的网站。PHP:电子邮件只适用于某些电子邮件客户端
我已经设置了一个注册/登录/忘记密码,除了忘记密码设置的问题之外,这些密码都可以使用。
如果用户的电子邮件地址是使用hotmail,yahoo,gmail等他们收到的电子邮件罚款,可以重置密码和数据库中的数据更改。
我在接收此电子邮件的个人域名电子邮件地址在Outlook和Mail中遇到问题,因此它看起来可能与Exchange有关?
我还启用了具有Outlook的计算机上的日志设置,并且在测试发送电子邮件时什么也没有记录,所以它不像它阻止电子邮件。
现在我有一个数组的电子邮件配置设置,我不确定它是否可以与主机,协议,头文件?或任何其他设置,但我会提供一些信息,以我的东西。如果任何人有任何信息,链接,片段或想法,这将是一个很大的帮助。
对于使用离子验证我刚才一直在那里它是,它改变了我的配置文件设置代码:
CONFIG
$config['use_ci_email'] = FALSE; // Send Email using the builtin CI email class, if false it will return the code and the identity
$config['email_config'] = array(
'protocol'=> 'mail',
'mailtype' => 'html',
'charset' =>'utf-8',
'smpt_host' =>'smpt.url.com',
'smpt_user'=> 'ssl://smtp.live.com',
'smtp_port' => '25',
'validate' => TRUE,
'priority' => 1
);
控制器,用于忘记密码:
//forgot password
function forgot_password() {
$this->form_validation->set_rules('email', 'Email Address', 'required');
if ($this->form_validation->run() == false) {
//setup the input
$this->data['email'] = array('name' => 'email',
'id' => 'email',
);
if ($this->config->item('identity', 'ion_auth') == 'username'){
$this->data['identity_label'] = 'Username';
}else{
$this->data['identity_label'] = 'Email';
}
//set any errors and display the form
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->_render_page('forgot_password', $this->data);
}else{
// get identity for that email
$config_tables = $this->config->item('tables', 'ion_auth');
$identity = $this->db->where('email', $this->input->post('email'))->limit('1')->get($config_tables['users'])->row();
//run the forgotten password method to email an activation code to the user
$forgotten = $this->ion_auth->forgotten_password($identity->{$this->config->item('identity', 'ion_auth')});
if ($forgotten) {
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("login", 'refresh'); //we should display a confirmation page here instead of the login page
}else{
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect("forgot_password", 'refresh');
}
}
}
function _get_csrf_nonce() {
$this->load->helper('string');
$key = random_string('alnum', 8);
$value = random_string('alnum', 20);
$this->session->set_flashdata('csrfkey', $key);
$this->session->set_flashdata('csrfvalue', $value);
return array($key => $value);
}
库函数for得到密码:
/**
* forgotten password feature
**/
public function forgotten_password($identity) //changed $email to $identity
{
if ($this->ion_auth_model->forgotten_password($identity)) //changed
{
// Get user information
$user = $this->where($this->config->item('identity', 'ion_auth'), $identity)->users()->row(); //changed to get_user_by_identity from email
if ($user)
{
$data = array(
'identity' => $user->{$this->config->item('identity', 'ion_auth')},
'forgotten_password_code' => $user->forgotten_password_code
);
if(!$this->config->item('email_config', 'ion_auth'))
{
$this->set_message('forgot_password_successful');
return $data;
}
else
{
$message = $this->load->view($this->config->item('email_templates', 'ion_auth').$this->config->item('email_forgot_password', 'ion_auth'), $data, true);
$this->email->clear();
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to($user->email);
$this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_forgotten_password_subject'));
$this->email->message($message);
if ($this->email->send())
{
$this->set_message('forgot_password_successful');
return TRUE;
}
else
{
$this->set_error('forgot_password_unsuccessful');
return FALSE;
}
}
}
else
{
$this->set_error('forgot_password_unsuccessful');
return FALSE;
}
}
else
{
$this->set_error('forgot_password_unsuccessful');
return FALSE;
}
}
我不知道你需要的确切配置。无论这里是我自己的send_mail()函数使用CI电子邮件库。它可以帮助你。不过,我总是使用ION AUTH,并且在发送邮件时我从不面临问题。
/*
* Send an email.
* $info array must have following information :
* $info = array(
* 'to_email' =>
* 'to_name' =>
* 'from_email' =>
* 'from_name' =>
* 'subject' =>
* 'body' =>
* 'reply_to' =>
*)
*/
if (! function_exists('send_email'))
{
function send_email($info)
{
$CI = & get_instance();
// ==========================================================================================
$CI->load->library('email');
$config['protocol'] = 'sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$CI->email->initialize($config);
$CI->email->clear();
$CI->email->set_newline("\r\n");
// =========================================================================================
$CI->email->from($info['from_email'], $info['from_name']);
$CI->email->to($info['to_email'], $info['to_name']);
$CI->email->cc('[email protected]', 'MAHBUB');
$CI->email->subject($info['subject']);
$CI->email->message($info['body']);
$CI->email->reply_to($info['reply_to'], "No reply");
if($CI->email->send()) return TRUE;
return FALSE;
}
}
我在这一刻也有同样的问题。这是我的解决方案,基于这个论坛帖子,这真的帮助我了解这个错误。
http://ellislab.com/forums/viewreply/785297/
在我的情况下,问题是使用的语言文件从存储库IonAuth我多语言设置。在德语语言文件中,您会发现'email_forgotten_password_subject'语言行的特殊字符'ü'。
Codeigniter邮件类未使用主题配置中的编码。所以specialchar编码不好,并出现smtp_mailer错误。
我已经创建了一个文件,应用程序/库/ MY_Email.php与此内容挂钩的使用受setter方法:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Email extends CI_Email
{
/**
* Set Email Subject
*
* @access public
* @param string
* @return void
*/
function subject($subject)
{
$subject = '=?'. $this->charset .'?B?'. base64_encode($subject) .'?=';
$this->_set_header('Subject', $subject);
}
}
现在Mailclass被编码题目的正确方法,我们都进入周末,喝些啤酒。
我希望我的解决方案符合您的问题。
干杯
你看过在host.url.com上的电子邮件日志吗?您是否使用电子邮件直播?如果是这样,你有权访问开发邮件服务器进行测试吗? – LeonardChallis 2013-02-15 11:52:58我目前正在本地主机上开发,也上传到服务器上,没有收到相关信息。当调试它说的是电子邮件发送,但表示电子邮件可能无法读取MIME编码的电子邮件 - 不知道这是我可以改变我的配置文件?还尝试了纯文本,将所有内容都镶嵌到后面,但仍然不是运气甚至错误。我使用了@ hotmail.co.uk,并且在Outlook Live浏览器,Gmail浏览器和雅虎浏览器中收到了该电子邮件。我不幸的是无法访问开发邮件服务器。 – Shimsham84 2013-02-15 12:02:33
您可以在本地安装类似hMail Server的服务器来测试邮件本地发送吗?你真的可以看到邮件服务器的实际日志。 – LeonardChallis 2013-02-15 12:04:35