Good Evening,
I'm using CodeIgniter 2 on IIS 8.5 and MSSQL Server,
When i tried to send an email in the process, it shows the error:
Severity: Notice
Message: A non well formed numeric value encountered
Filename: libraries/Email.php
Line Number: 1689
I've been using this code for some projects in the same server, and it's working properly. But when i tried to implement on this one it always shows this error everytime there's sending email process.
And here's my controller:
function reset_pass() {
if (!IS_AJAX) {
display_nonajax_stop();
exit;
} else {
$settings = $this->m_setting->get_setting_array();
$min_pass_length = (int) $settings["acc_pass_min_length"];
$data = $this->input->post();
$id = $data['id'];
$hasil = array();
$kondisi = array(
"usr_id" => $id
);
$current_time = waktu_sekarang();
$baris = $this->m_ess->get_user_employee_row($kondisi);
$user = $baris;
if ($user->usr_email === NULL) {
$hasil['pesan'] = "User does not have valid email associated . Please contact Administrator.";
$hasil['status'] = 0;
} else {
$this->load->helper('email');
if (!valid_email($user->usr_email)) {
$hasil['pesan'] = "User does not have valid email associated . Please contact Administrator.";
$hasil['status'] = 0;
} else {
$hasil['pesan'] = "Username and email is ok";
$hasil['status'] = 0;
$this->load->library('rndconditionpass');
$tmppass = $this->rndconditionpass->get_random_string($min_pass_length);
$new_password = $this->bcrypt->do_hash($tmppass);
$mail_data['random'] = $tmppass;
$mail_data['username'] = $user->usr_name;
$mail_data['full_name'] = $user->emp_name;
$mail_data['password'] = $tmppass;
//prepare data to be used in leo_mail library
$param = array();
$param['recipient'] = $user->usr_email;
$param['content'] = $this->load->view("template/mail/mail_reset_pass", $mail_data, TRUE);
$param['subject'] = "Reset Password";
$this->load->library('leo_mail');
$kirim = $this->leo_mail->kirim($param);
if ($kirim['status'] == 1) {
#password history
$insert_pass = array(
"pas_usr_name" => $user->usr_name,
"pas_password" => $new_password,
"pas_date" => $current_time,
"pas_opid" => $this->session->userdata("usr_name"),
"pas_update" => $current_time
);
$this->m_pass->insert_pass($insert_pass);
$hasil['pesan'] = "Password has been reset and user has been notified via email. ";
$hasil['status'] = 1;
//update the database, store the reset code
$update = array();
$update['usr_last_cpass'] = date("Y-m-d H:i:s");
$update['usr_needchgpwd'] = "Y";
$update["usr_password"] = $new_password;
$kondisi = array("usr_name" => $user->usr_name);
$q = $this->m_ess->update_user($update, $kondisi);
} else {
$hasil['pesan'] = "Fail to send email your password reset code.";
$hasil['status'] = 0;
}
}
}
echo json_encode($hasil);
}
}
and here's the '$this->leo_mail->kirim function
function kirim($param) {
$q=$this->ci->m_smtp->get_mail_konfig();
$hasil=array();
if($q->num_rows()<1) {
$hasil['pesan']="Your SMTP configuration has not been set up properly";
$hasil['status']=0;
} else {
if(valid_email($param['recipient'])) {
$config=array();
$config_data= $q->row();
$config['protocol'] = "smtp";
$config['useragent'] = "HRISSMTPLIB";
$config['smtp_port'] = $config_data->smt_smtp_port;
$config['smtp_host'] = $config_data->smt_smtp_host;
$config['smtp_user']= $config_data->smt_smtp_user;
$config['smtp_pass']= $this->ci->leo_enkripsi->decrypt($config_data->smt_smtp_pass,$this->key);
$config['newline']="\r\n";
$config['wordwrap'] = FALSE;
$config['starttls']=($config_data->smt_encrypt_type==3)?TRUE:FALSE;
$config['mailtype'] = "html";
$this->ci->email->initialize($config);
$this->ci->email->from($config_data->smt_email,$config_data->smt_name);
$this->ci->email->to($param['recipient']);
$this->ci->email->subject($param['subject']);
$this->ci->email->message($param['content']);
if($this->ci->email->send()) {
$hasil['pesan']="Email sent";
$hasil['status']=1;
} else {
$hasil['pesan']= $this->ci->email->print_debugger();
$hasil['status']=0;
}
} else {
$hasil['pesan']="Recipient email is not valid";
$hasil['status']=0;
}
}
return $hasil;
}
Sorry for my bad english.
Thank you in advance.
Related
this is the image of database table.
I'm new at codeigniter PHP
public function ForgotPassword($email)
{
$this->db->select('email');
$this->db->from('member');
$this->db->where('email', $email);
$query=$this->db->get();
$out = $query->result_array();
if (count($out) > 0) {
$email = $out[0]['email'];
return array('status'=>1, 'email'=>$email);
} else {
return array('status'=>0, 'msg'=>'email not found');
}
}
This is my model function., this line giving me blank result $out = $query->result_array(); I don't know why, it should give me email address so that i can proceed and send email. I want to send password to user using forgot password function.
public function ForgotPassword()
{
$email = $this->input->post('email');
$findemail = $this->MY_model->ForgotPassword($email);
if ($findemail['status'] == 1) {
$this->MY_model->sendpassword($findemail);
} else {
echo " $email not found, enter correct email id";
}
}
And this is my controller function. Here I'm getting blank value of $findemail. I don't know why.
public function sendpassword($data)
{
$email = $data['email'];
$query1=$this->db->query("SELECT * from member where email = '".$email."' ");
$row=$query1->result_array();
if ($query1->num_rows() > 0) {
$passwordplain = "";
$passwordplain = rand(10000000,99999999);
$newpass['password'] = md5($passwordplain);
$this->db->where('email', $email);
$this->db->update('member', $newpass);
$mail_message='Dear '.$row[0]['username'].','. "\r\n";
$mail_message.=' Your <b>Password</b> is
<b>'.$passwordplain.'</b>'."\r\n";
require 'C:\xampp\htdocs\phpmailer\class.phpmailer.php';
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSendmail();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$subject = 'Testing Email';
$mail->AddAddress($email);
$mail->IsMail();
$mail->From = 'vishal#gmail.com';
$mail->FromName = 'admin';
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $mail_message;
$mail->Send();
if (!$mail->send()) {
echo "Failed to send password";
} else {
echo "Password sent ! check your mail";
}
} else {
echo "Email not found!!!!";
}
}
And also upper model function , it's not sending email. I'm using phpmailer to sending email. Please help.
If your model name is 'MY_model' then write construct function in your controller file and load the model into it as shown below.
function __construct() {
parent::__construct();
$this->load->model('my_model');
}
And modify your ForgotPassword function of controller as below.
public function ForgotPassword()
{
$email = $this->input->post('email');
$findemail = $this->my_model->ForgotPassword($email);
if ($findemail['status'] == 1) {
$this->my_model->sendpassword($findemail);
} else {
echo " $email not found, enter correct email id";
}
}
I hope this helps.
I have made a function that checks if email exists in db. It is named CheckUser().
Then in ForgotPassword() you call CheckUser() ($email must be given as argument).
<?php
public function CheckUser($email)
{
$response = $bdd->prepare('SELECT email FROM member WHERE email = :email');
$response->execute([
"email" => $$email
]);
$data = $response->fetchAll();
return $data[0];
}
public function ForgotPassword($email)
{
// here you call our new function
** UDPATE BELOW CALLING OF CHECKUSER FUNCTION **
$out = $this->CheckUser($email);
// sizeof will return the lenght of the returned data from our CheckUser() function
if (sizeof($out) > 0){
$email = $out[0]['email'];
return array('status'=>1, 'email'=>$email);
}
else {
return array('status'=>0, 'msg'=>'email not found');
}
}
Let me know if it works.
i have code like this
<?php
require('../config.php');
require_once($CFG->dirroot . '/user/editlib.php');
$errorMessage = '';
$successMessage = '';
if(isset($_SESSION['successMessage']))
{
$successMessage = $_SESSION['successMessage'];
unset($_SESSION['successMessage']);
}
if (isset($_POST['register'])) {
if(!preg_match("/^(?=.*[0-9])(?=.*[a-z])(\S+)$/i", $_POST['password']))
{
$errorMessage="don't allow spaces";
}
$errors = array();
$data = array();
$chk_sql = "SELECT * FROM {user} u where username = ?";
if (!empty($chk_sql) ) {
$errorMessage='Username already taken';
}
if(!$chk_username = $DB->get_record_sql($chk_sql, array($_POST['username'])) )
{
$secret = $_POST['secret'];
$access_code_sql = "SELECT * FROM {accesscode} WHERE random_no= ? and status=1";
if($chk_secret = $DB->get_record_sql($access_code_sql, array($secret)) )
{
if ( $chk_secret->used >= $chk_secret->number ) {
$errorMessage = "your access code limit completed..";
}
else
{
$cadminid = $chk_secret->cadmin_id;
$clientid = $chk_secret->clientid;
$DB->execute("UPDATE {accesscode} SET used = used+1 WHERE random_no = '$secret'");
$insert_record = new stdClass();
$insert_record->firstname = $_POST['firstname'];
$insert_record->lastname = $_POST['lastname'];
$insert_record->username = $_POST['username'];
$insert_record->secret = $secret;
$insert_record->password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$insert_record->timecreated = time();
$insert_record->maildigest = $cadminid;
$insert_record->maildisplay = $clientid;
$insert_record->idnumber = 1;
$insert_record->mnethostid = 1;
$insert_record->confirmed = 1;
$insert_record->email = $_POST['email'];
if($result = $DB->insert_record('user', $insert_record))
{
$_SESSION['successMessage'] = "record created successfully";
header('Location: register.php');
}
else
$errorMessage = "error! can you please try again";
}
}
else
$errorMessage = "your access code is wrong..";
}
}
?>
so i want to write condition like another if condition
if ( $chk_secret->status='0' ) {
$errorMessage = "your access code deactivated..";
}
if not they can register
i tried..but i didn't get idea where i have to add that if..
before i have condition like if number>used it will show some error message like your accesscode limit completed
can anyone help me..
thanks in advance..
= is for value assignment
== is compare two operands
so you need to change
if ( $chk_secret->status='0' ) {
to
if ( $chk_secret->status=='0' ) {
UPDATE:
your query SELECT * FROM {accesscode} WHERE random_no= ? and status=1
which means it going to return only status == 1
you can check with number of rows returned is ZERO then through status zero error message.
Or else
Get rows only based on random_no exists and then check status key
i try to add a user to freeipa with the code below. the code return success but when i go to the freeipa UI the user is not visible. if i try to reinsert it will fail telling that user already exist. what can be? thanks
$con = ldap_connect($server);
ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
// bind anon and find user by uid
$user_search = ldap_search($con,$dn,"(|(uid=admin))");
$user_get = ldap_get_entries($con, $user_search);
$user_entry = ldap_first_entry($con, $user_search);
$user_next = ldap_next_entry($con, $user_entry);
$user_dn = ldap_get_dn($con, $user_next);
if (ldap_bind($con, $user_dn, "adminpass") === false) {
$message[] = "Error E101 - Current Username or Password is wrong.";
}else{
$info['givenName'] = "test";
$info['cn'] = "test";
$info['sn'] = "user";
$info['mail'] = "test#localhost";
$info['objectclass'][0] = "inetorgperson";
if(ldap_add($con, "cn=test,cn=users,cn=accounts,dc=domain,dc=net", $info) === false){
$error = ldap_error($con);
$errno = ldap_errno($con);
$message[] = "$errno - $error";
}else{
$message[] = "ok";
}
}
I'm trying to fetch email from inbox using php imap(). In localhost function works fine but on our bluehost based dedicated server it showing following error
[an error occurred while processing this directive]
Php Code
$imap = #imap_open("{mail.******.com:143/novalidate-cert}", "a****i#*****.com", "******");
if(isset($imap)){
$message_count = #imap_num_msg($imap);
$array_mail = array();
if($message_count > 0){
for ($m = 1; $m <= $message_count; ++$m){
//$header = #imap_header($imap, $m);
$header = #imap_rfc822_parse_headers(imap_fetchheader($imap, $m));
$email[$m]['from'] = $header->from[0]->mailbox.'#'.$header->from[0]->host;
//$email[$m]['fromaddress'] = $header->from[0]->personal;
//$email[$m]['to'] = $header->to[0]->mailbox;
//$email[$m]['cc'] = $header->cc[0]->mailbox;
//$email[$m]['subject'] = $header->subject;
//$email[$m]['message_id'] = $header->message_id;
//$email[$m]['date'] = $header->udate;
//$from = $email[$m]['fromaddress'];
$from_email = $email[$m]['from'];
$array_mail[] = $from_email;
if(isset($header->cc)){
$hedCC = $header->cc;
foreach($hedCC as $s){
echo $s->mailbox.'#'.$s->host.'<br />';
//$array_mail[] = $s->mailbox.'#'.$s->host;
}
}
if(isset($header->to)){
$hedTO = $header->to;
foreach($hedTO as $t){
echo $t->mailbox.'#'.$t->host.'<br />';
//$array_mail[] = $t->mailbox.'#'.$t->host;
}
}
}
$i = 0;
if (!empty($array_mail)) {
$insertCount = 0;
foreach($array_mail as $m_){
// INSERT HERE
//echo $m_.'<br />';
$isExistWithID = $this->isExistWithID($user_id,$m_);
$email_err = $this->isValidEmail($m_);
$isValid = 0;
if($email_err == false){
$isValid = 1;
}
if($isExistWithID==0 && $isValid==0){
$insert = $this->pdoConnection->prepare("
INSERT INTO ws_email (
u_id,
we_email,
date_added
)
VALUES(
:u_id,
:we_email,
:date_added
)
");
$insert->bindParam(':u_id', $u_id);
$insert->bindParam(':we_email', $we_email);
$insert->bindParam(':date_added', $date_added);
// Insert Data
$u_id = $_SESSION['USERID'];
$we_email = $m_;
$date_added = date("Y-m-d H:i:s");
if($insert->execute()){
$insertCount++;
}
}
$i++;
}// end foreach
$response['success'] = $insertCount . ' Email address(s) fetched successfully.';
}
//echo $i;
//
}else{
$response['error'] = 'No record found';
}
}else{
$response['error'] = 'IMAP does not connect';
}
/************ END NEW 29 SEP *************/
echo json_encode($response, JSON_PRETTY_PRINT);
Can anyone kindly guide me where is the issue that i can fix. I would like to appreciate. Thank You.
EDITED
I added ticket to host provider. Following are the comments,
This error is because of a the FCGI timeout. This can be fixed by changing to suphp. You can change the php type in the whm to suphp on the Main >> Service Configuration >> Apache Configuration >> PHP and SuExec Configuration page. I suggest to closely watch the website with that to suphp as it makes the server more vulnerable to scripts running unchecked.
In my Yii web application I want to write a web service for mobile application. I create a url for access student details with GET method. That I want to change GET method to POST method or PUT method. My url is,
url/index.php/user/login/studentdetails/?username=demo
I am getting this username from client side and giving the response from server side to client side in json format.
My code is,
public function actionStudentdetails() {
if (isset($_GET['username'])) {
$user = Users::model()->findByAttributes(array('username' => $_GET['username']));
$usertypeid = $user->usertypeid;
if ($usertypeid === '1') {
$studentid = $user->userid;
} else if ($usertypeid === '3') {
$guardianid = $user->userid;
$studentid = $_GET['studentid'];
} else {
$employeemasterid = $user->userid;
}
$student = Student::model()->findByPk($studentid);
header('Content-type: application/json');
$response["student_admissionno"] = $student->student_admissionno;
$response["student_firstname"] = $student->student_firstname;
$response["student_middlename"] = $student->student_middlename;
$response["student_lastname"] = $student->student_lastname;
$response["student_admissiondate"] = $student->student_admissiondate;
$response["student_dob"] = $student->student_dob;
$response["student_gender"] = $student->student_gender;
$response["student_religion"] = $student->student_religion;
$response["student_caste"] = $student->student_caste;
$response["student_address1"] = $student->student_address1;
$response["student_address2"] = $student->student_address2;
$response["student_city"] = $student->student_city;
$response["student_state"] = $student->student_state;
$response["success"] = 1;
$response["message"] = "success";
echo json_encode($response);
}
}
}
Please help me.
you can try this code for webserivce. you can used any method GET or POST Method of data posting in server side.
StudentController.php
public function actionStudentdetails() {
$json_data = array();
$params = isset($_REQUEST) ? $_REQUEST: "";
if (!empty($params)) {
$username = $params['username'];
if($username == "") {
$json_data['success'] = false;
$json_data['message'] = 'Username are required.';
} else {
$user = Users::model()->findByAttributes(array('username' => $params['username']));
$usertypeid = $user->usertypeid;
if ($usertypeid === '1') {
$studentid = $user->userid;
} else if ($usertypeid === '3') {
$guardianid = $user->userid;
$studentid = $_GET['studentid'];
} else {
$employeemasterid = $user->userid;
}
$student = Student::model()->findByPk($studentid);
header('Content-type: application/json');
$json_data["student_admissionno"] = $student->student_admissionno;
$json_data["student_firstname"] = $student->student_firstname;
$json_data["student_middlename"] = $student->student_middlename;
$json_data["student_lastname"] = $student->student_lastname;
$json_data["student_admissiondate"] = $student->student_admissiondate;
$json_data["student_dob"] = $student->student_dob;
$json_data["student_gender"] = $student->student_gender;
$json_data["student_religion"] = $student->student_religion;
$json_data["student_caste"] = $student->student_caste;
$json_data["student_address1"] = $student->student_address1;
$json_data["student_address2"] = $student->student_address2;
$json_data["student_city"] = $student->student_city;
$json_data["student_state"] = $student->student_state;
$json_data['success'] = true;
$json_data['message'] = "Data found Successful.";
}
} else {
$json_data['success'] = false;
$json_data['message'] = "Please try again.";
}
echo json_encode($response);
}