Order confirmation emails not working in Magento 1.9.3.2 - magento

My website is live and the order confirmation emails are neither being sent to the customer nor the admin. I am using Magento 1.9.3.2.

Please check whether Cron jobs are working or not, you can check easily by installing AOE SCHEDULER extension, make sure you have proper setting in System > Configuration > Advanced > System > Cron Also check whether you entered sender email in System > configuration> Sales> Sales email > Order emails.

Just to add to the above, out of the box the cronjobs are pre-configured in Magento, but you need to setup the actual job on your servers cron tab.
In SSH open the crontab;
crontab -e
Add this;
### MAGENTO CRON ###
*/1 * * * * cd /path/to/magento/ && sh cron.sh
Replaced /path/to/magento with the actual path your installation.

Magento allow 2 way to send email like below :
1) Using cron
2) Avoid cron
If you want without cron then use below change:
Open your order.php file at - app/code/core/Mage/Sales/Model/Order.php
And change :
//$mailer->setQueue($emailQueue)->send(); **// Comment this code.**
to:
$mailer-> send();
Note : Above change is not standard way in magneto so please implement file override way.
Go to : app/design/frontend/base/default/template/checkout/success.phtml:
Add following code on the top of the file code :
$order = Mage::getModel('sales/order');
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order->loadByIncrementId($incrementId);
try
{
$order->sendNewOrderEmail();
}
catch (Exception $ex)
{
echo "Email Not Sent...";
}
$customer = Mage::getSingleton('customer/session')->getCustomer();
$email = $customer->getEmail();

Related

Schedule Joomla Site Offline

I'm wondering if anyone has more details on how to schedule Joomla to be set to "Offline/Maintenance Mode" at a specific date and time. I found this post here on stack overflow and I'm wondering if anyone has been successful in either (1) implementing a custom plugin to add this functionality, or (2) via a script that sets the site into offline/maintenance mode and perhaps a cronjob to run the script at specific time or if (3) maybe there is an extension that already exists that simply adds this offline/maintenance mode scheduling feature.
Based on the previous post I linked to above I'm not sure if a plugin would work or how best to go about the script and cronjob technique. From my understanding based on the responses in the post, it sounded like the script and cronjob would be the only way to accomplish this. If someone can let me know if they were successful implementing this and how that would be great or any suggestions or direction on how to go about it would be helpful.
Using a plugin for such little would not worth it in my opinion.
I would rather use a little script like:
<?php
// Make sure this is only called through command line
if (php_sapi_name() !== "cli") die('Only command line');
// Replace by your joomla configuration file path
$configuration_file_path = '/var/www/joomla/configuration.php';
if (!empty($argv[1])) {
$offline = 1;
} else {
$offline = 0;
}
// Retrieve configuration file content
$configuration_content = file_get_contents($configuration_file_path);
// Replace the offline line by the calculated value
$configuration_content = preg_replace('/(.*)public \$offline =(.*)/m', '$1public $offline = \'' . $offline . '\';' , $configuration_content);
// Write back the configuration file
file_put_contents($configuration_file_path, $configuration_content);
This script can be called through the command line:
php offline.php 1 #to enable offline status
php offline.php 0 #to disable offline status
If you need to run it through a cronjob by editing /etc/crontab or add it in your hosting settings:
# Offline at 4AM each day
0 4 * * * www-data php /path/of/your/script/offline.php 1 >> /dev/null 2>&1
# Online at 4:05AM each day
5 4 * * * www-data php /path/of/your/script/offline.php 0 >> /dev/null 2>&1

Codeigniter url in crontab

How to set codeigniter url in crontab
I have tried with
* * * * * php-cli /var/www/html/msp/index.php partner cron_test
But it did not work
My application url is
localhost/msp/index.php/partner/cron_test
My php code
public function cron_test()
{
if($this->input->is_cli_request())
{
$fo= fopen("/var/www/cron_test".microtime().".txt", "w") or die("Unable to open file!");;
fwrite($fo,"Cron tab test");
fclose($fo);
}
else
{
echo "You dont have access";
}
}
Project located under /var/www/html/
Set correct php installation path or directly use php in command to execute your cron, if you want to find out your installation path try using command.
which php
It will give you installation path like used in below crontab command
* * * * * /usr/bin/php /var/www/html/msp/index.php partner cron_test
If you want to debug your cron url, you can directly run /usr/bin/php /var/www/html/msp/index.php partner cron_test command from Ubuntu terminal. It will show you the direct output So you can debug wheather it's working or not then set in crontab accordingly.

Magento cron job issue

I am having email sending issue in magento and I think it is due to cron jobs, following are the setting
cron job settings on cpanel
cron job settings on magento
I just cant figure out the issye
To Set Cron on Server:
You can set cron job on server for every 5 minutes:
php -f /home/fullpath/public_html/cron.php
Debug:
If cron Job still not work, Please add following code:
$isShellDisabled = true;
After below line of code:
$isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;

cronjob in codeigniter using cpanel

My website hosting server is hostmonster.com.
My application uses codeigniter framework.
I have a code which sends emails to my users and I want to make it automatic.
I have used the cpanel of the hosting service and I tried to give the command as
php -q www.mysite.com/admin admin sendDailyEmail
my controller is admin and the method is sendDailyEmail and the controller is present inside the application/controllers/admin folder.
I have also set a reminder email to me whenever the cronjob is run.
The email subject reads
Cron php -q /home1/username/public_html/admin admin sendDailyEmail
and the body says
No input file specified
Where do I go wrong.
I have never run cronjobs and this is my first time.
I am no good in giving command line instuctions too.
My admin sendDailyEmail code is as follows
function sendDailyEmail() {
$data = $this->admin_model->getDailyData();
foreach ($data as $u) {
if($u->Daily){
//if(!$u->Amount){
if ($u->Email=='myemail#gmail.com') {
$user['user_data']['FirstName'] = $u->FirstName;
$user['user_data']['LastName'] = $u->LastName;
$user['user_data']['Id']=$u->Id;
$this->email->clear();
$this->email->to($u->Email);
$this->email->from('alerts#mysite.com', 'MySite');
$this->email->subject("My Subject");
$msg = $this->load->view('emails/daily_view', $user, true);
$this->email->message($msg);
if ($this->email->send())
$data['message'] = "Daily Emails has been sent successfully";
else
$data['message'] = "Daily Emails Sending Failed";
}
}
}
$data['main_content']['next_view'] = 'admin_home_view';
$this->load->view('includes/admin_template', $data);
}
You can use wget and set the time for whatever you like:
wget http://www.mysite.com/admin/sendDailyEmail
You can also use curl:
curl --silent http://www.mysite.com/admin/sendDailyEmail
For CodeIgniter 2.2.0
You can try this:
php-cli /home/username/public_html/index.php controller method
or at your case
php-cli /home/username/public_html/index.php admin sendDailyEmail
It works fine with me..
Cheers!
Codeigniter sets up command line differently for running crons, etc.
Read:
http://www.codeigniter.com/user_guide/general/cli.html
So you should run:
php index.php admin admin sendDailyEmail
(that may need adjusted; based on your code above)
Have a look at an article I just wrote that goes a little deeper into it all:
http://codebyjeff.com/blog/2013/10/setting-environment-vars-for-codeigniter-commandline
i have facing same issue while, but following work for me
wget http://www.yoursite.com/controller/function

CodeIgniter Cron Job on Shared Hosting?

I am trying to learn how to do my first cron job using CodeIgniter. In the past, it seemed the only way to do this with CI was to use the wget command instead of php.
The CodeIgniter User Guide, however, says that now you can do this from the command line, for example by running:
$ cd /path/to/project;
$ php index.php controller method
This works great using Terminal on my local setup. But when I use a similar command in the cron section of cPanel on my shared hosting, the task just returns the contents of index.php.
I'm not entirely sure what cPanel does with this command, so unsure as to whether it's using the command line at all.
Could someone explain how I might be able to set up a cron job on shared hosting using CodeIgniter please?
Here is the example code from the CodeIgniter user guide:
tools.php
public function message($to = 'World')
{
echo "Hello {$to}!".PHP_EOL;
}
}
?>
It's going to depend on your host. Cron jobs could really screw stuff up if you're not careful, so a lot of shared hosts don't allow it. You probably need to be on some virtual container (like a VPS, virtuozo, etc.) to do this. This isn't a CodeIgniter issue, but a hosting provider issue. Call them first.
We worked around this exact issue as follows:
Set up a normal php file that is scheduled by cron. Nothing to do with codeigniter yet
Inside it, you can make an fsocket or curl request to perform your regular CodeIgniter call as you do from the web.
Here's an example (say, cron.php)
#!/usr/local/bin/php.cli
<?php
DEFINE('CRON_CALL_URL','https://my_server/'); //
DEFINE('CRON_HTTPS_PORT', 443); // port to use during fsocket connetion
DEFINE('CRON_SSL_PREFIX', 'ssl://'); // prefix to be used on the url when using ssl
$current_time = now();
$md5_hash = md5('somevalue'.$current_time);
$url = CRON_CALL_URL.'MYCTRL/MYMETHOD';
$parts=parse_url($url);
//
$parts['query']='md5_hash='.$md5_hash.'&time='.$current_time;
$fp = fsockopen(CRON_SSL_PREFIX.$parts['host'],
isset($parts['port'])?$parts['port']:CRON_HTTPS_PORT,
$errno, $errstr, 30);
if (!$fp) {
} else {
if (!array_key_exists('query', $parts)) $parts['query'] = null;
$out = "POST ".$parts['path']." HTTP/1.1\r\n";
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($parts['query'])."\r\n";
$out.= "Connection: Close\r\n\r\n";
if (isset($parts['query'])) $out.= $parts['query'];
fwrite($fp, $out);
fclose($fp);
}
}
?>
NOTE: Make sure that in your MYCTRL/MYMETHOD function you have
ignore_user_abort(true);
that way when you fsocket connection is closed, your script will still run to the end.
We actually have a bunch of these fsockets for various reasons. If you need to make sure that the call to that controller/method came from the cron script, you need to pass some additional hash values so that only cron and the script know it. Once the script is called it has access to any codeigniter functions. Works like a charm.
I've set up 100s of CI cronjob on shared hosting like this: create a short php script which calls the CI controller as if it was a webbrowser.
So, script.php contains this:
script #! /usr/local/bin/php -f /home/example/public_html/script.php
<?php
get_get_contents('http:example.com/cronjob/');
?>
Then set your cronjob in cPanel to call script.php
When it runs Script.php will call the Codeigniter Cronjob controller. There you have the entire CI framework at your disposal.
If you are going to call it like a web browser, why not replace the cronjob
command with:
wget http://example.com/cronjob/
instead of creating something new or simply
curl --suppress http://example.com/cronjob/`

Resources