2016-12-14 206 views
1

我想使用的PHPMailer這裏我控制器代碼發送電子郵件使用的PHPMailer

public function register(){ $this->form_validation->set_rules('username', 'Usename Name', 'trim|required|min_length[3]|max_length[30]'); 
    $this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email|is_unique[employer_registration.email]'); 
    $this->form_validation->set_rules('mobile', 'Mobile', 'trim|required|numeric'); 
    $this->form_validation->set_rules('password', 'Password', 'trim|required|md5'); 
    if ($this->form_validation->run() == FALSE) 
    { 
     $this->load->view('employer/emp_register'); 
    } 
    else 
    { 
     $data = array(
      'username' => $this->input->post('username'), 
      'email' => $this->input->post('email'), 
      'mobile' => $this->input->post('mobile'), 
      'password' => $this->input->post('password') 
     ); 
     $email = $this->input->post('email'); 
     $username = $this->input->post('username'); 
    // insert form data into database 
     if ($this->Employer_model->insertUser($data)) 
     { 
      require 'PHPMailerAutoload.php'; 
      require 'class.phpmailer.php'; 
      $mail = new PHPMailer; 
      $mail->isSMTP(); 
      $mail->SMTPAuth = true; 
    $subject = 'Testing Email'; 
      $username = $username; 
      $email = $email; 
      $body = "Thank you for register your username is $username"; 
      $mail->AddAddress($email); 
      $mail->IsMail(); 
      $mail->From = 'domainname.com'; 
      $mail->IsHTML(true); 
      $mail->Subject = $subject; 
      $mail->Body = $body; 
      $mail->Send(); 

      if(!$mail->send()) 
      { 
       echo "<script>alert('Sorry! mail not sent')</script>"; 
       echo 'Mailer Error: ' . $mail->ErrorInfo; 
      } 
      else 
       { 
       echo "<script>alert('Email sent to $email mail id')</script>"; 
       } 
    }}} 

我已經下載PHPMailer的文件夾,從GitHub發送郵件,包括它在我的項目PHPMailerAutoload文件仍然成功註冊我無法發送郵件後註冊電子郵件ID。我得到錯誤,如梅勒錯誤:無法實例化郵件功能。

+1

笨有一個電子郵件庫。 – user4419336

+0

請參閱下面的答案。 – Ionut

+0

使用CI郵件庫。 –

回答

1

您使用SMTP身份驗證,但是你沒有實際定義任何主機,這是必需的:

例:$mail->Host = "smtp.example.com";

端起$mail->isSMTP();後與您的域名改變。

此外,您還可以選擇像這樣提供用戶名和密碼,如果你需要:

$mail->Username = 'username'; $mail->Password = 'password';

+1

謝謝你現在在工作 – Tejaswee

相關問題