Codeigniter 3:发送帐户激活电子邮件失败 [英] Codeigniter 3: send account activation email fails

查看:114
本文介绍了Codeigniter 3:发送帐户激活电子邮件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CodeIgniter 3和Twitter Bootstrap开发注册和登录应用程序.

I am working on a Register and Login application with CodeIgniter 3 and Twitter Bootstrap.

当用户 注册 时,应将电子邮件发送至他/她提供的地址以及帐户确认链接.问题在于确认电子邮件未发送.

When a user registers, an email should be send to the address he/she provided, with an account confirmation link. The problem is that the confirmation email does not send.

用户模型中,我有:

public function activationEmail($first_name='', $last_name='', $email='', $verification_key='')
{
    $this->load->library('email');
    $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'smtp.code-love.tk',
        'smtp_port' => 465,
        'smtp_user' => 'razvan@code-love.tk',
        'smtp_pass' => '******',
        'smtp_crypto' => 'ssl',
        'mailtype'  => 'html', 
        'charset'   => 'iso-8859-1'
    );

    $messg = 'Wellcome, '. $first_name . ' ' . $last_name . '! Click the <strong><a href="'.site_url('/signin/activateaccount/'. $verification_key).'">confirmation link</a></strong> to confirm your account.';


    $this->email->initialize($config); 
    $this->email->set_newline('\r\n');
    $this->email->from('mail.code-love.tk','Razvan Zamfir'); 
    $this->email->to($email);
    $this->email->subject('Account activation');
    $this->email->message($messg);
     if (!$this->email->send()) {
    show_error($this->email->print_debugger());
}
  else {
    echo 'Your e-mail has been sent!';
  }
}

在我的注册控制器中,我有以下代码:

In my Signup controller I have this code:

public function signup() {
    $this->form_validation->set_rules('first_name', 'First name', 'required');
    $this->form_validation->set_rules('last_name', 'Last name', 'required');
    $this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
    $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]');
    $this->form_validation->set_rules('cpassword', 'Confirm password', 'required|matches[password]');
    $this->form_validation->set_error_delimiters('<p class="error">', '</p>');

    if ($this->form_validation->run()) {
        $first_name = $this->input->post('first_name');
        $last_name = $this->input->post('last_name'); 
        $email =  $this->input->post('email');
        $password = $this->input->post('password');
        $verification_key = md5($email);
        $date_created = date('Y-m-d H:i:s');
        $date_updated = date('Y-m-d H:i:s');
        $active = 0;
        // Load user model
        $this->load->model('Usermodel');

        // If email does not already exist in the database 
        // signup new user
        if (!$this->Usermodel->email_exists($email)) {
            if ($this->Usermodel->user_register($first_name, $last_name, $email, $password, $verification_key, $date_created, $date_updated, $active) && $this->Usermodel->activationEmail($first_name, $last_name, $email, $verification_key)) {

                $this->session->set_flashdata("signup_success", "Your account has just bean created. You must confirm it before you can sign in. We have send you a confirmation email at $email for this purpose.");

            } else {
                // unless sigup does not fail for whatever reason
                $this->session->set_flashdata("signup_failure", "We ware unable to create your account.");
            }
            redirect('signup'); 
        } else {
            // If email is already in the database
            // urge user to sign in (redirect to signup page too)
            $this->session->set_flashdata("email_exists", "The email address $email already exists in the database. Please signin.");
            redirect('signin'); 
        }
    } else {
        $this->load->view('signup');
    }
}

确实发生了注册 ,并且出现了错误,并且验证电子邮件未发送.我不是从本地XAMPP/WAMP/MAMP服务器执行此操作,而是从实时"服务器执行此操作,您可以

The sign up does happen, with the error below, and the verification email is not send. I am not doing this from a local XAMPP/WAMP/MAMP server, but from a "live" one, you can signup yourself.

Severity: Warning

Message: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known

Filename: libraries/Email.php
Line Number: 1950

Backtrace:
File: /home/roxoqdat/code-love.tk/ciauth/application/models/Usermodel.php
Line: 52
Function: send

File: /home/roxoqdat/code-love.tk/ciauth/application/controllers/Signup.php
Line: 42
Function: activationEmail

File: /home/roxoqdat/code-love.tk/ciauth/index.php
Line: 292
Function: require_once

我在做什么错了?

推荐答案

检查您是否具有必需的SMTP服务. 尝试使用Google SMTP服务.

Check if you have the required SMTP service. Try with google SMTP service.

    $config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

$this->email->from('mygmail@gmail.com', 'myname');
$this->email->to('target@gmail.com'); 

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');  


$result = $this->email->send();

接下来尝试:

  $config = array('mailtype' => 'html'); 

从$ config = array中删除其余部分.

Remove the rest from $config = array.

这篇关于Codeigniter 3:发送帐户激活电子邮件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆