0

So i have written a custom module to do some stuff, but part of that stuff is to register a new member into EE. All of that is working great, but, it doesn't send the self activation email out (even though EE is configured too).

I have no idea what i'm missing here codewise? From looking through the EE code, it should send the email. I get no errors either.

$this->EE->load->model('member_model');
$this->EE->load->helper('security');

$data['username']     = $this->input->post('username');
$data['password']    = do_hash($this->input->post('password'));
$data['email']        = $this->EE->input->post('email');
$data['ip_address']    = $this->EE->input->ip_address();
$data['unique_id']    = random_string('encrypt');
$data['join_date']    = $this->EE->localize->now;
$data['language']     = $this->EE->config->item('deft_lang');
$data['timezone']     = ($this->EE->config->item('default_site_timezone') && $this->EE->config->item('default_site_timezone') != '') ? $this->EE->config->item('default_site_timezone') : $this->EE->config->item('server_timezone');
$data['daylight_savings'] = ($this->EE->config->item('default_site_dst') && $this->EE->config->item('default_site_dst') != '') ? $this->EE->config->item('default_site_dst') : $this->EE->config->item('daylight_savings');
$data['time_format'] = ($this->EE->config->item('time_format') && $this->EE->config->item('time_format') != '') ? $this->EE->config->item('time_format') : 'us';
$data['group_id'] = 1;

if ($this->EE->member_model->get_members('', '', '', $data['username'], '', 'username')->num_rows() > 0)
{
   $this->EE->output->show_user_error('submission', 'Username already exists!!!!');
}

$member_id = $this->EE->member_model->create_member($data);

$this->EE->member_model->delete_member($member_id); 

1 Answer 1

1

The email are being sent with help of Email library. In the code you posted, there is no reference for it, therefore no emails go out.

Here is sample code for sending member activation email from one of my add-ons (you might need to modify it to match your needs)

if ($this->EE->config->item('req_mbr_activation') == 'email')
{
    $action_id  = $this->EE->functions->fetch_action_id('Member', 'activate_member');

    $name = ($data['screen_name'] != '') ? $data['screen_name'] : $data['username'];

    $board_id = ($this->EE->input->get_post('board_id') !== FALSE && is_numeric($this->EE->input->get_post('board_id'))) ? $this->EE->input->get_post('board_id') : 1;

    $forum_id = ($this->EE->input->get_post('FROM') == 'forum') ? '&r=f&board_id='.$board_id : '';

    $add = ($mailinglist_subscribe !== TRUE) ? '' : '&mailinglist='.$_POST['mailinglist_subscribe'];

    $authcode_data = array('authcode' => $this->EE->functions->random('alnum', 10));

    $swap = array(
        'name'              => $name,
        'activation_url'    => $this->EE->functions->fetch_site_index(0, 0).QUERY_MARKER.'ACT='.$action_id.'&id='.$authcode_data['authcode'].$forum_id.$add,
        'site_name'         => stripslashes($this->EE->config->item('site_name')),
        'site_url'          => $this->EE->config->item('site_url'),
        'username'          => $data['username'],
        'email'             => $data['email'],
        'password'          => $password
     );

    $email_subject = ($this->settings['email_subject']!='')?$this->settings['email_subject']:$this->email_subject;
    $email_template = ($this->settings['email_template']!='')?$this->settings['email_template']:$this->email_template;
    $template_q = $this->EE->functions->fetch_email_template('mbr_activation_instructions');
    $email_tit = $this->_var_swap($email_subject, $swap);
    $email_msg = $this->_var_swap($email_template, $swap);

    // Send email
    $this->EE->load->helper('text');

    $this->EE->load->library('email');
    $this->EE->email->wordwrap = true;
    $this->EE->email->from($this->EE->config->item('webmaster_email'), $this->EE->config->item('webmaster_name'));
    $this->EE->email->to($data['email']);
    $this->EE->email->subject($email_tit);
    $this->EE->email->message(entities_to_ascii($email_msg));
    $this->EE->email->Send();

    $this->EE->db->where('member_id', $member_id);
    $this->EE->db->update('members', $authcode_data);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.