I made a system for sending e-mail but I need to put a interval in the send, today I only show the sending using an "echo" but if you have a progress it would be even better.
I don't know what the best way to do it when I tried to send with more than 3000 contacts was a timeout, but it remained sending.
I found function sleep, but I don't know if it would be suitable for the current code.
$locale = DB::table('email_contact')
->where('list_id','=',$list)
->get();
for($i = 0;$i < count($locale);$i++){
if($creditemail < count($locale)){
echo "you not credit!";
break;
}else{
$sender = $locale[$i];
$sending = $sender[$i]->email;
$name = $sender[$i]->name;
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = false;
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = 'host';
$mail->SMTPAuth = true;
$mail->Username = 'user';
$mail->Password = 'pass';
$mail->SMTPSecure = false;
$mail->Port = 587;
//Recipients
$mail->setFrom('mail#my.com', 'Mail - My');
$mail->addAddress($sending, $name); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $text;
$mail->send();
$number = $i+1;
DB::table('users')
->where('id','=',Auth::id())
->decrement('email_credit', 1);
echo 'Sender: '.$number.'/'.count($locale)."<br>";
}catch (\Exception $e){
echo $e;
}
}
}
Use laravel mailer. You can easily add a delay there and also you can improve the code quality as well. Have a look at the documentation https://laravel.com/docs/7.x/mail
$when = now()->addMinutes(10);
Mail::to($request->user())
->cc($moreUsers)
->bcc($evenMoreUsers)
->later($when, new OrderShipped($order));
Related
Using XAMPP for running codeigniter getting blank screen everytime in localhost. Other codeigniter project working well
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "";
// The following values can probably stay the same.
$db['default']['hostname'] = "";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$active_group = "default";
$active_record = TRUE;
A blank screen usually means you have missed a " ; " someplace. I would say check your syntax completely. The missing ; might be in your view, controller or in the model. Almost any syntax error can bring you a blank screen
When my maintenance mode is on.
I would like to be able to still view the home page when maintenance mode is on.
But only if the member session role_id = 1
Currently does not let me view the home page at all even though my session role_id == 1 keeps redirecting to maintenance page
Question: How can I make sure can view home page if maintenance mode is active but if session role id == '1'
public function maintenance_mode() {
$maintenance_mode = $this->is_maintenance();
if ($maintenance_mode) {
if ($this->session->userdata('role_id') == '1') {
return true;
} else {
$route = $this->uri->segment(1) .'/'. $this->uri->segment(2);
$ignore = array('common/maintenance');
if (!in_array($route, $ignore)) {
redirect(base_url('common/maintenance'));
}
}
}
}
public function is_maintenance() {
$query = $this->db->where('item', 'maintenance_mode')->get('settings')->row('value');
return $query;
}
Solution
The code in my question was fine. I found the issue. it was creating the sessions twice one for www.example.co.nz and one for example.co.nz
I need to add cookie domain
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '.example.co.nz';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_sessions';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = APPPATH . 'cache/sessions/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
I am generating orders from a custom web service called from a mobile app. However when the order is finally generated, I get "Original Price" as Rs0.00 . This is creating a problem since we have third party integrations for invoicing and Shipping.
However in the normal course of action when order is generated from website, the Original Price is correct.
I inspected the sales_flat_order_item table for both these orders, the original_price is indeed 0.00 in the first order, Hence I must be missing something in my code which is not setting the original_price for the orderItem.
Here is the code where the quote is converted to order.
public function placeorder($custid, $Jproduct, $store, $address, $couponCode, $is_create_quote, $transid, $payment_code, $shipping_code, $currency, $message)
{
$res = array();
$quantity_error = array();
try {
$quote_data = $this->prepareQuote($custid, $Jproduct, $store, $address, $shipping_code, $couponCode, $currency, 1, 0);
if ($quote_data["status"] == "error") {
return $quote_data;
}
$quote = Mage::getModel('sales/quote')->load($quote_data['quote_id']);
$quote = $this->setQuoteGiftMessage($quote, $message, $custid);
$quote = $this->setQuotePayment($quote, $payment_code, $transid);
$convertQuote = Mage::getSingleton('sales/convert_quote');
try {
$order = $convertQuote->addressToOrder($quote->getShippingAddress());
}
catch (Exception $Exc) {
echo $Exc->getMessage();
}
$items = $quote->getAllItems();
foreach ($items as $item) {
$orderItem = $convertQuote->itemToOrderItem($item);
$order->addItem($orderItem);
}
try {
$decode_address = json_decode(base64_decode($address));
$order->setCustomer_email($decode_address->billing->email);
$order->setCustomerFirstname($decode_address->billing->firstname)->setCustomerLastname($decode_address->billing->lastname);
}
catch (Exception $e) {
}
$order->setBillingAddress($convertQuote->addressToOrderAddress($quote->getBillingAddress()));
$order->setShippingAddress($convertQuote->addressToOrderAddress($quote->getShippingAddress()));
$order->setPayment($convertQuote->paymentToOrderPayment($quote->getPayment()));
$order->save();
$quantity_error = $this->updateQuantityAfterOrder($Jproduct);
$res["status"] = 1;
$res["id"] = $order->getId();
$res["orderid"] = $order->getIncrementId();
$res["transid"] = $order->getPayment()->getTransactionId();
$res["shipping_method"] = $shipping_code;
$res["payment_method"] = $payment_code;
$res["quantity_error"] = $quantity_error;
$order->addStatusHistoryComment("Order was placed using Mobile App")->setIsVisibleOnFront(false)->setIsCustomerNotified(false);
if ($res["orderid"] > 0 && ($payment_code == "cashondelivery" || $payment_code == "banktransfer" || $payment_code == "free")) {
$this->ws_sendorderemail($res["orderid"]);
$order->setState(Mage_Sales_Model_Order::STATE_NEW, true)->save();
$res["order_status"] = "PENDING_PAYMENT";
} else {
$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true)->save();
$res["order_status"] = "PENDING_PAYMENT";
}
}catch (Exception $except) {
$res["status"] = 0;
$res["shipping_method"] = $shipping_code;
$res["payment_method"] = $payment_code;
}
return $res;
}
It would be very helpful if someone points out what I missed. I will edit if any other info is required.
Missing original_price indicates that you didn't run collectTotals() on the quote yet, try the following:
$quote->collectTotals()->save();
$order->save();
I am using Codeigniter 2.0.1 and Postgresql 8.1. My code uses transactions within try-catch blocks.
On a simple insert at times I get a "Fatal Error"
Fatal Error: Call to a member function row() on a non-object in
<...path...>/system/database/drivers/postgre/postgre_driver.php on
line 357
My Database Config is:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "***";
$db['default']['password'] = "***";
$db['default']['database'] = "***";
$db['default']['dbdriver'] = 'postgre';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
The lne of my Model code that is causing the error is "$id = $this->db->insert_id();".
I say so because the line that causes the error is within insert_id() method and it is being used only once in the model.
A code snapshot of the model is given below.
try {
// CODE TO FILL UP $data ARRAY
$this->DBquery("BEGIN");
$this->DBinsert('<TABLE NAME>', $data);
$id = $this->db->insert_id();
// SOME MORE CODE
}
catch(Exception $e) {
$this->DBquery("ROLLBACK");
//echo $e->getMessage();
return 0;
}
$this->DBquery("COMMIT");
return $id;
$this->DBquery and $this->DBinsert are custom methods made by me on a base model class which extends the CI_Model class. These methods function full well.
Below is the insert_id method in postgre_driver.php and line 357 is "$row = $query->row();"
function insert_id()
{
$v = $this->_version();
$v = $v['server'];
$table = func_num_args() > 0 ? func_get_arg(0) : NULL;
$column = func_num_args() > 1 ? func_get_arg(1) : NULL;
if ($table == NULL && $v >= '8.1')
{
$sql='SELECT LASTVAL() as ins_id';
}
elseif ($table != NULL && $column != NULL && $v >= '8.0')
{
$sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
$query = $this->query($sql);
$row = $query->row();
$sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
}
elseif ($table != NULL)
{
// seq_name passed in table parameter
$sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
}
else
{
return pg_last_oid($this->result_id);
}
$query = $this->query($sql);
$row = $query->row(); // LINE 357
return $row->ins_id;
}
Its so more confusing because the problem is not always. It happens sometimes but with a good enough frequency to hamper work. The system is being used by about 8-10 users and so I guess concurrency should not be an issue.
Also, I am using pconnect and number of connections is unlimited.
This sounds like maybe some of your insert statements are failing. If something errors out inside of a transaction like this, it can invalidate the transaction. If you look in the log file, you may find entries like "current transaction is aborted, commands ignored until end of transaction." (What's happening is the $query variable in the insert_id function doesn't receive a valid query result value, so calling functions on it fails at that point)
The best way to handle this is probably to modify your custom DBinsert function to return a value indicating the success or failure of the insert operation. (You should just be able to return the value of whatever insert command you're running internally)
Then, you can do something like this:
$insert_ret_val = $this->DBinsert('<TABLE NAME>', $data);
if($insert_ret_val){
//insert success!
$id = $this->db->insert_id();
}else{
//handle failed insert here, rollback, whatever
}
i have this code
$specific['hostname'] = "localhost";
$specific['username'] = "root";
$specific['password'] = "";
$specific['database'] = "ci_forsyria";
$specific['dbdriver'] = "mysql";
$specific['dbprefix'] = "";
$specific['pconnect'] = FALSE;
$specific['db_debug'] = FALSE;
$specific['cache_on'] = FALSE;
$specific['cachedir'] = "";
$specific['char_set'] = "utf8";
$specific['dbcollat'] = "utf8_general_ci";
$specific_db = $this->load->database($specific, TRUE);
i use this parameter "FALSE" to hide connection error !
$specific['db_debug'] = FALSE;
but how i can create custom error message if connection field
like
$connect = $this->db->connect;
if(!$connect)
{
// print error message ..
}
DB_Debug is designed to show Database error messages.
You have turned that functionality off with "$specific['db_debug'] = FALSE;"
So instead you need to turn it back on, and filter the $error message on the error_db.php file.
i.e. inside error_db.php
<? php if ($message === 'Database connection error')
{
echo $message;
}
else
{
echo "error - sorry";
} ?>
or something like that