這是我在用戶註冊時發送電子郵件的代碼。每封郵件到達用戶電子郵件需要5分鐘或更長時間。我不知道爲什麼電子郵件需要花費太多時間才能到達。如果我正在發送具有相同功能的電子郵件sendEmail()不帶僅帶有簡單文本的驗證碼。現在需要1分鐘或1分半鐘來訪問用戶的電子郵件。使用Codeigniter發送電子郵件需要很多時間
有時甚至在鏈接末尾發送驗證碼時,它甚至不會發送任何電子郵件。
我不知道如何發送電子郵件與SMTP。我發現了一些例子,他們將他們的域名添加到smtp_host,電子郵件,密碼中,該電子郵件是使用域創建的。我做了同樣的事情,但沒有發生我的電子郵件發送。這與我是否使用SMTP幾乎一樣。
這是我的功能名稱sendEmail(),我創建了模型來發送電子郵件。我之所以在模型中創建這個功能,是因爲我也必須從其他控制器發送電子郵件。 我不會,如果它可能是發送電子郵件的問題
請看看這個功能,我做錯了。或者如果還有其他方法,請告訴我如何做到這一點。或者任何類型的建議對我都很有幫助。
控制器
function index() {
//my validation rules are here
if ($this->form_validation->run() == TRUE) {
$data = $this->fetch_data_from_post();
$user_email = $data['email'];
$code = random_string('unique');
$verification_link = base_url('Home/verify/').$code;
$subject = "Confirmation Message";
$message = "Dear User,\n\n\nPlease click on Given below URL to verify your Email Address ".$verification_link." \n\n Once you click on the above link then your account will be verified and you will get an opportunity to login. See you soon,Thank You...!\n";
$email_sent = $this->Perfect_mdl->sendEmail($user_email,$subject,$message);
if($email_sent != 1){
$flash = '<div class="alert alert-danger">Opppssss Somthing went Wrong...</div>';
$this->session->set_flashdata('user_registration',$flash);
redirect('Home/signup');
}else{
$this->Perfect_mdl->_insert($data);
$flash = '<div class="alert alert-success">You are Successfully Registered... Please Check Your Email <b>'.$user_email.'</b> For Verification</div>';
$this->session->set_flashdata('user_registration',$flash);
redirect('Home/signup');
}
}
$data['meta_title'] = "Signup";
$data['services_name'] = $this->Perfect_mdl->getServices_home();
$dat['flash'] = $this->session->flashdata('user_registration');
$this->load->view('signup',$data);
}
型號: -
function sendEmail($useremail,$subject,$message) {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.mydomainname.com',
'smtp_port' => 25,
'smtp_user' => '[email protected]', // change it to yours
'smtp_pass' => 'vishal123456', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'crlf' => "\r\n",
'newline' => "\r\n",
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->from('[email protected]', 'Company Name');
$this->email->to($useremail);
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send()){
return "1";
}else{
return "0";
}
}
爲什麼你使用'SMTP'從不同的服務器發送代碼?如果它全部在本地主機上,那麼就不需要'SMTP' – ArtisticPhoenix
我不知道smtp是如何工作的。我使用smtp儘可能快地發送到達用戶電子郵件的原因。不,我用這個服務器。 –
刪除該smpt配置陣列..在現場主機不需要使用此smtp配置.. – Mahesh