2016-07-04 7 views
1

Ich möchte mit PHP CodeIgniter einen E-Mail-Verifikationslink an den Benutzer senden.E-Mail-Verifikationslink mit php condeigniter gesendet

Dies ist meine Controller-Funktion.

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' => '[email protected]', 
     'smtp_pass' => 'password' 
    ); 

    $this->load->library('email',$config); 
    $this->email->set_newline("\r\n"); 
    $this->email->isHTML(true); 
    $this->email->from("[email protected]"); 
    $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()); 
    } 
} 

Beachten Sie, dass ich E-Mails von meinem localhost sende. Ich erhalte die E-Mail, aber das Problem ist, dass sie auch die HTML-Tags anzeigt. Dies ist die E-Mail, die ich erhielt:

Please use the link below to activate your account..<br /><br /><br /><a 
href='http://localhost/tutorhunt/MainController/Confirm_Activation/[email protected]' 
target='_blank'>VERIFY EMAIL</a><br /><br /><br />Kind regards,<br />Company 
Name 
+0

Verwenden '$ msg = "VERIFY EMAIL


";' – Poonam

+0

Haben Sie einen Fehler haben.? Weißt du, ob die E-Mail gesendet wird oder nicht? Hast du Junk-Mail eingecheckt? – Julqas

+0

Vielleicht ... es ist nicht richtig "Redirect" -Funktion zu verwenden. –

Antwort

0

Versuchen E-Mail-Bibliothek zu initialisieren und Mailtype hinzufügen, wie

folgenden
$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', 
    )); 
0

Um Bestätigungslink in E-Mail über E-Mail-Vorlage ist einfacher zu senden als HTML-Inhalt als Nachricht hinzugefügt und sende es.

  • Erstellen Sie ein Array der Variablen, die Sie in einer E-Mail senden möchten.
  • Laden Sie diese E-Mail-Vorlagenansicht und laden Sie dieses Variablenfeld und legen Sie die Variable in der Vorlage richtig fest. Hier

ist das Codebeispiel:

$this->email->set_newline("\r\n"); 
$this->email->isHTML(true); 
$this->email->from("[email protected]"); 
$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()); 
} 
Verwandte Themen