duanhe1903 2016-07-04 10:12
浏览 215

发送电子邮件验证链接与php codeigniter

I want to send an email verification link to the user with PHP CodeIgniter.

This is my controller function.

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("
");
    $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());
    }
}

Note that I am sending emails from my localhost. I receive the email but the problem is it shows the html tags as well. This is the email which I received:

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
  • 写回答

2条回答 默认 最新

  • dongtang7347 2016-07-04 12:30
    关注

    Try to initialize email library and add mailtype as following

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

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突