这是我的主要功能我无法使用本地服务器在codeigniter中发送电子邮件。帮助解决此问题
用户注册成功,但没有收到任何电子邮件。
public function register(){
$this->load->view("Home/home_header");
if(isset($_POST["user_register"])){
$this->form_validation->set_rules('name', 'First Name', 'alpha|htmlspecialchars|trim|required');
$this->form_validation->set_rules('username', 'Last Name', 'htmlspecialchars|trim|required');
$this->form_validation->set_rules('email', 'Email', 'valid_email|trim|required');
$this->form_validation->set_rules('confirm-mail', 'Confirm Email', 'valid_email|trim|required|matches[email]');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confirm-password', 'Confirm Password', 'required|matches[password]');
$this->form_validation->set_rules('address', 'Address', 'htmlspecialchars|trim|required');
$this->form_validation->set_rules('country', 'Country', 'required');
$this->form_validation->set_rules('male-female', 'Gender', 'required');
if($this->form_validation->run() == TRUE){
$status = 0;
$data = array();
$data["first-name"] = $_POST["name"];
$data["username"] = $_POST["username"];
$data["mail"] = $_POST["email"];
$data["confirm-mail"] = $_POST["confirm-mail"];
$data["password"] = hash('md5',$_POST["password"]);
$data["confirm-password"] = hash('md5',$_POST["confirm-password"]);
$data["address"] = $_POST["address"];
$data["country"] = $_POST["country"];
$data["male-female"] = $_POST["male-female"];
$data["status"] = $status;
$email = $_POST["email"];
$saltid = md5($email);
if($this->db->insert("register",$data)){
if($this->User_functions->sendmail($email,$saltid)){
//echo 'Succesful';
redirect(base_url().login);
}else{
echo "Sorry !";
}
}
}
}
$this->load->view("Home/user_registration");
$this->load->view("Home/home_footer");
}
而这里的邮件功能。我从输入中获取用户电子邮件并将用户记录存储到数据库。成功记录商店并将页面重定向到登录页面。但用户在注册时不会收到电子邮件。帮我解决这个问题。
function sendmail($email,$saltid){
// configure the email setting
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com'; //smtp host name
$config['smtp_port'] = '465'; //smtp port number
$config['smtp_user'] = '*******@gmail.com';
$config['smtp_pass'] = '***********'; //$from_email password
$config['mailtype'] = 'html';
//$config['charset'] = 'iso-8859-1';
//$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
//$this->email->initialize($config);
$this->load->library('email', $config);
$url = base_url()."user/confirmation/".$saltid;
$this->email->from('[email protected]', 'GulfPro');
$this->email->to($email);
$this->email->subject('Please Verify Your Email Address');
$message = "<html><head><head></head><body><p>Hi,</p><p>Thanks for registration with DGaps.</p>
<p>Please click below link to verify your email.</p>".$url."<br/><p>Sincerely,</p><p>DGaps Team</p></body></html>";
$this->email->message($message);
return $this->email->send();
}
如果我为此使用了任何错误的代码,还会突出显示该代码。
感谢 阿马尔·哈利克
您是否已在gmail中授予应用程序使用该服务的权限? –
不要将密码分享给公众 –
谢谢,先生。下次我会小心的。 –