我想使用的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。我得到錯誤,如梅勒錯誤:無法實例化郵件功能。
笨有一個電子郵件庫。 – user4419336
請參閱下面的答案。 – Ionut
使用CI郵件庫。 –