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.
Related
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.
I want to send some parameters from an HTML file with Ajax (jQuery) to my PHP file, which is also on the bplaced.net server. Near to everything is fine, my Ajax method sends the parameters to the PHP file, the PHP file receives them and is also connected with my Mysql database. The only problem when I try to insert in a table of the database nothing happens (no faults) table is still empty.
<?php
header('Access-Control-Allow-Origin: *');
// Verbindung herstellen //
#$verbindung = mysql_connect("localhost","username","password","database");
//Variablen
$a1 = $_POST["a1"];
$a2 = $_POST["a2"];
$a3 = $_POST["a3"];
$a4 = $_POST["a4"];
$a5 = $_POST["a5"];
$a6 = $_POST["a6"];
$a7 = $_POST["a7"];
$a8 = $_POST["a8"];
$a9 = $_POST["a9"];
$a10 = $_POST["a10"];
$a11 = $_POST["a11"];
$a12 = $_POST["a12"];
$a13 = $_POST["a13"];
$a14 = $_POST["a14"];
$a15 = $_POST["a15"];
$a16 = $_POST["a16"];
$a17 = $_POST["a17"];
$a18 = $_POST["a18"];
$a19 = $_POST["a19"];
$a20 = $_POST["a20"];
$a21 = $_POST["a21"];
$a22 = $_POST["a22"];
$a23 = $_POST["a23"];
$a24 = $_POST["a24"];
$a25 = $_POST["a25"];
$a26 = $_POST["a26"];
$a27 = $_POST["a27"];
$a28 = $_POST["a28"];
$a29 = $_POST["a29"];
$a30 = $_POST["a30"];
$a31 = $_POST["a31"];
$a32 = $_POST["a32"];
$a33 = $_POST["a33"];
$a34 = $_POST["a34"];
$a35 = $_POST["a35"];
$a36 = $_POST["a36"];
// Einfügen
$eintrag = "INSERT INTO test (name) VALUES ('tim')";
$eintragen = mysql_query($eintrag);
if($eintragen) {
echo "Eintrag war erfolgreich";
} else {
echo "Fehler beim Speichern";
}
mysql_close($verbindung);
?>
It echoes: "Fehler beim Speichern".
(PS: The other variables are not yet in use).
Use this code to find out if the Connection is ok:
try {
$verbindung = mysql_connect("localhost","username","password","database");
} catch (Exception $e) {
echo 'Exception vorhanden: ', $e->getMessage(), "\n";
}
// Code fortsetzen
The Same with this piece of code to find out if your insert is working:
Try { $eintragen = mysql_query($eintrag);}
I have hundreds of response from php IMAP (fetching email), I wanted to insert all the fetched email into database. Problem is that on server stay time is 40 second (Host provider said to me) and my script is taking more than 40 second. Due to the fetching records and insert queries server returning the following error.
[an error occurred while processing this directive]
Here is Php Code
$imap = #imap_open("{mail.******.com:143/novalidate-cert}", '*****#***.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;
$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 if error is equal to 0
/************ END NEW 29 SEP *************/
echo json_encode($response, JSON_PRETTY_PRINT);
I tried to optimize the code as i can, but still taking long time and due to this server returning the error.
I would like to request to you kindly guide me how can i optimize it. Thank You.
I have created a json for getting mysql data for a news app in android & ios. Whenever I am parsing the json.php file it returns "No tag defined" and the app stopped working both android and ios. Here is the code sample that I was trying to work out.
<?php
header('content-type: application/json; charset=utf-8');
$con = mysql_connect("localhost","####","###");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("###", $con);
$date = date('Y-m-d');
//$date = '2014-02-01';
$year = substr($date, 0, -6);
$month = substr($date, 5, -3);
$day = substr($date,-2, 10);
if($month==01) $month1="january";
else if($month==02) $month1="february";
else if($month==03) $month1="march";
else if($month==04) $month1="april";
else if($month==05) $month1="may";
else if($month==06) $month1="june";
else if($month==07) $month1="july";
else if($month==08) $month1="august";
else if($month==09) $month1="september";
else if($month==10) $month1="october";
else if($month==11) $month1="november";
else if($month==12) $month1="december";
$table=$month1.$year;
//$table = $february2014;
if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ''){
$tag = $_REQUEST['tag'];
if($tag =='category_page' && isset($_REQUEST['menu_id']) && $_REQUEST['menu_id'] !='' ) {
$menu_id = $_REQUEST['menu_id'];
try{
$i=0;
$query = mysql_query("SELECT * FROM $table WHERE menu_id=1 AND news_date ='$date'");
if($query === FALSE) {
die(mysql_error());
}
while($data=mysql_fetch_array($query)){
$responce[$i]['news_id'] = $data['news_id'];
$responce[$i]['news_title'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_title']),0,110)));
$responce[$i]['news_reporter'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_reporter']),0,110)));
$responce[$i]['news_details'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_details']),0,110)));
$responce[$i]['photo'] = $data['photo'];
$responce[$i]['path'] = 'admin/'.str_replace('\\','',$data['path']);
$responce[$i]['menu_id'] = $data['menu_id'];
$responce[$i]['menu_type'] = $data['menu_type'];
$responce[$i]['news_publish_status'] = $data['news_publish_status'];
$responce[$i]['news_order'] = $data['news_order'];
$responce[$i]['news_date'] = $data['news_date'];
$responce[$i]['news_time'] = $data['news_time'];
$responce[$i]['added_by'] = $data['added_by'];
$responce[$i]['directory'] = $data['directory'];
$responce[$i]['read_number'] = $data['read_number'];
$responce[$i]['comment_number'] = $data['comment_number'];
$responce[$i]['news_comment_table_name'] = $data['news_comment_table_name'];
$i++;
}
} catch(Exception $e) {
$responce = 'Exception: '.$e->getMessage();
}
}else{
$responce = "category or Menu id is not Defined";
}
echo json_encode($responce);
}else{
echo json_encode("No tag Defined");
}
?>
not getting any way to fix it up. can any one help me out.Would appreciate your kind assistance.
Try this
if(isset($_REQUEST['tag'])){
Instead of
if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ''){
A lot of versions around but i can not get it right...
I need to transfer variables from one php script file to another.
script1.php has the variables:
$t1 = $_POST['t1'];
$t2 = $_POST['t2'];
and I need to work with these variables in another script file - script2.php
How can I access these variables in script2.php file?
OK. i will post all the script.
script1.php or in fact getImage.php is following
<?php
$today = date("Ymd_His");
$t1 = $_POST['t1']; //mazais nosaukums
$t2 = $_POST['t2']; //lielais nosaukums
$c1 = $_POST['c1']; //kjeksis
$c2 = $_POST['c2']; //kjeksis
$c3 = $_POST['c3']; //kjeksis
$c4 = $_POST['c4']; //kjeksis
$mazais = $_POST['mazais']; //maza bilde atseviskji
$lielais = $_POST['lielais']; //maza bilde atseviskji
$response = "";
$error_response = "error.php";
$succes_response = "nextstep.php";
$etikjete = base64_decode($_REQUEST['png']);
if ($handle1 = fopen("render/".$today.'.png', 'w+')) {
if (!fwrite($handle1, $etikjete) === FALSE) {
fclose($handle1);
$response .= "Success etikjete! ";
} else {
$response .= "fwrite error etikjete! ";
$error = true;
}
} else {
$response .= "fopen error etikjete! ";
$error = true;
}
if($mazais){
$etikjete = base64_decode($mazais);
if ($handle1 = fopen("render/".$today.'_mazais.png', 'w+')) {
if (!fwrite($handle1, $etikjete) === FALSE) {
fclose($handle1);
$response .= "Success mazais! ";
} else {
$response .= "fwrite error mazais! ";
$error = true;
}
} else {
$response .= "fopen error mazais! ";
$error = true;
}
}
if($lielais){
$etikjete = base64_decode($lielais);
if ($handle1 = fopen("render/".$today.'_lielais.png', 'w+')) {
if (!fwrite($handle1, $etikjete) === FALSE) {
fclose($handle1);
$response .= "Success lielais! ";
} else {
$response .= "fwrite error lielais! ";
$error = true;
}
} else {
$response .= "fopen error lielais! ";
$error = true;
}
}
if($error){
echo $error_response;
} else {
echo $succes_response;
}
?>
and script2.php here is called nextstep.php
and in this nextstep.php I need to save the variables from getImage.php into database. nextstep.php so far is like this but does not work. connection with db is ok, if I set different independent variables on nextstep.php then they gets stored into db.
<?php
include 'getImage.php';
// Connects to your Database
mysql_connect("localhost", "user", "pass") or die(mysql_error()) ;
mysql_select_db("myDB") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO jos_orders (maza_bilde,liela_bilde,mazais_nosaukums,lielais_nosaukums)
VALUES ('$t1', '$c2', '$mazais', '$lielais')") ;
?>
How about these:
Session - store your data to session variables to that it can be retrieve to any pages of your site. The data will be cleared when you close your browser.
session_start();
$_SESSION['t1'] = $_POST['t1'];
$_SESSION['t2'] = $_POST['t2'];
Get Variable = Pass the variable through the URL
page2.php?t1=somevars&t2=somevars
$t1 = $_GET['t1'];
$t2 = $_GET['t2'];
3.$_COOKIE[] - http://www.w3schools.com/php/php_cookies.asp
You want to access the variables from a different script so it seems you are redirecting your script else all the global variables are accessible from any script as we know. So the solution can be session, else you if you are just doing some insert or update or delete action I suggest you submit it to the same page and include a file pass an action value check it from the included file perform the action according to that and redirect. Another solution is to built a small mvc application take a look at some mvc applications code I hope you can understand. Hope this will help you.
You can create them in $_SESSION[]
Check this out :
Storing Form Data as a Session Variable