发送电子邮件验证链接与PHP condeigniter


sent email verification link with php condeigniter

我想用PHP CodeIgniter发送一个电子邮件验证链接给用户。

这是我的控制器功能。

public function Sent_Confirmation_Email()
{
    $emailid  = $this->uri->segment(3);
    $verificationLink = base_url() . 'MainController/Confirm_Activation/'.$emailid;
    $msg .= "Please use the link below to activate your account..<br /><br /><br />";
    $msg .= "<a href='".$verificationLink."' target='_blank'>VERIFY EMAIL</a><br /><br /><br />";
    $msg .= "Kind regards,<br />";
    $msg .= "Company Name";         
    if( ! ini_get('date.timezone') )
    {
        date_default_timezone_set('GMT');
    }        
    $config = array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'sender@gmail.com',
        'smtp_pass' => 'password'
    );
    $this->load->library('email',$config);
    $this->email->set_newline("'r'n");
    $this->email->isHTML(true);
    $this->email->from("sender@gmail.com");
    $this->email->to("$emailid");
    $this->email->subject("Email Confirmation - Courses and Tutors");
    $this->email->message($msg);
    if($this->email->send())
    {
    $this->session->set_flashdata('msg', 'A confirmation email has been sent to ' . $emailid .'. Please activate your account using the link provided.');
        redirect(base_url() . 'MainController/EConfirmationPage/'.$emailid);
    } else {
        show_error($this->email->print_debugger());
    }
}

请注意,我是从本地主机发送电子邮件的。我收到的电子邮件,但问题是它显示的html标签以及。这是我收到的邮件:

Please use the link below to activate your account..<br /><br /><br /><a
href='http://localhost/tutorhunt/MainController/Confirm_Activation/fareedshuja@gmail.com'
target='_blank'>VERIFY EMAIL</a><br /><br /><br />Kind regards,<br />Company
Name

尝试初始化电子邮件库并添加如下邮件类型

    $this->email->initialize(array(
          'protocol'  => 'smtp',
          'smtp_host' => 'ssl://mailserver',
          'smtp_user' => 'user',
          'smtp_pass' => 'password',
          'smtp_port' => 465,
          'crlf'      => "'r'n",
          'newline'   => "'r'n",
          'mailtype'  => 'html',
    ));

在电子邮件中发送验证链接使用电子邮件模板比添加HTML内容作为消息并发送更简单。

  • 创建一个你想在邮件中发送的变量数组。
  • 加载电子邮件模板视图,加载变量数组,并在模板中正确设置变量。
下面是代码示例:
$this->email->set_newline("'r'n");
$this->email->isHTML(true);
$this->email->from("sender@gmail.com");
$this->email->to("$emailid");
$this->email->subject("Email Confirmation - Courses and Tutors");   
$template_data = array(
        'verificationLink' => base_url() . 'MainController/Confirm_Activation/'.$emailid,
        'message' => 'Please use the link below to activate your account..',
        'company_name' => 'test company'                            
);
$body = $this->load->view ('your_view.php', ['template_data'=>$template_data], TRUE); //Set the variable in template Properly
$this->email->message ( $body );
if($this->email->send())  
{
    $this->session->set_flashdata('msg', 'A confirmation email has been sent to ' . $emailid .'. Please activate your account using the link provided.');
    redirect(base_url() . 'MainController/EConfirmationPage/'.$emailid);
} else {
    show_error($this->email->print_debugger());
}