Problem with the cronjob - The cronjob is not sending newsletters
Problem with the cronjob - The cronjob is not sending newsletters
Hello guys! I am a begginer and I hope that you can help me.
I need to send newsletters to the users who registred. I'm not talking about spam. But for this, I need to make a cronjob with the newsletter script!
Right now the site is under construction. So, for example. If I try the cron job every 3 minutes, the site should give me a newsletter to every 3 minutes. But it doesn't send me anything. I used this cmd: "wget http://domain.ro/cron/newsletter_auto.php And Cron Daemon sends me this:
Where is the problem?
I need to send newsletters to the users who registred. I'm not talking about spam. But for this, I need to make a cronjob with the newsletter script!
Right now the site is under construction. So, for example. If I try the cron job every 3 minutes, the site should give me a newsletter to every 3 minutes. But it doesn't send me anything. I used this cmd: "wget http://domain.ro/cron/newsletter_auto.php And Cron Daemon sends me this:
Code: Select all
--2016-09-11 01:27:01-- http://www.domain.ro/cron/newsletter_auto.php
Resolving www.domain.ro (www.domain.ro)... IP
Connecting to www.domain.ro (www.domain.ro)|IP|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 53 [text/html]
Saving to: ‘newsletter_auto.php.282’
Re: Problem with the cronjob - The cronjob is not sending newsletters
Hello,
You should use something like this:
Replacing the username and domain to match the one you use.
You should use something like this:
Code: Select all
php -q /home/admin/web/domain.tld/public_html/cron/newsletter.php
Re: Problem with the cronjob - The cronjob is not sending newsletters
I'm just wondering if php-cli, started from Cron, has open_basedir.......
Re: Problem with the cronjob - The cronjob is not sending newsletters
I've tried with this command. I've got the same results as with the command "/usr/bin/php -q /home/admin/web/voucher-email.ro/public_html/cron/newsletter.php". Basically, Cron Daemon just sends me an email everytime this cronjob should run with the last part of the php script, "<br><br>TOTAL TIME: 0.0004 seconds". But the newsletter is not working.mike08 wrote:Hello,
You should use something like this:
Replacing the username and domain to match the one you use.Code: Select all
php -q /home/admin/web/domain.tld/public_html/cron/newsletter.php
Here is the newsletter.php code:
Code: Select all
<?php
error_reporting(0);
ini_set('error_reporting', 0);
ini_set('display_errors', 0);
ini_set('log_errors', 0);
$base = dirname(dirname(__FILE__)); // now $base contains "app"
$siteroot = $base.'/';
$themeroot = $base.'/theme/general/';
include $base.'/include/func.php';
$siteroot = $base.'/';
$themeroot = $base.'/theme/general/';
error_reporting(0);
ini_set('error_reporting', 0);
ini_set('display_errors', 0);
ini_set('log_errors', 0);
###################################################
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
###################################################
#echo $siteroot;
$now = strtotime(date('d.m.Y').' 00:01');
$ora = date('H');
$qn = mysql_query("select *
from newsletter_auto
where status='1' and '$now' > (last_send + freq)
order by id asc
limit 5 "); # and (last_send='0' or last_send='')
while ($n = mysql_fetch_array($qn)){
#echo '<br>'.$n['mail'].' -- '.$n['last_send'];
echo '<br>'.$n['id'].' -- '.$n['last_send'];
##############
if ($n['cuvant']!=''){
$sql_tip_anunt = " and ( p.titlu LIKE '%".$n['cuvant']."%' ) ";
}
if ($n['judet']!=''){
$sql_tip_anunt = " and ( u.judet = '".$n['judet']."' ) ";
}
$created_start = $n['last_send'];
$created_end = $n['last_send'] + $n['freq']; #($n['last_send'] ? $n['last_send'] : $n['created']) + $n['freq'];
#$sql_tip_anunt = '';
#
$q_property = mysql_query("
select p.*
from product p left join user u on p.user_id=u.id
where p.status='1' and ('".date('U')."' between p.pub_start and p.pub_end) and (p.created between '".$created_start."' and '".$created_end."') ".$sql_tip_anunt." "); # limit 5
$nr_property = mysql_num_rows($q_property);
if ($nr_property>0){
$subject = $nr_property.' oferte noi - '.date('d.m.Y').' - '.$settings['sitename'];
$message = 'Buna ziua, <strong>'.$n['name'].'</strong><br><br>Va anuntam prin acest email faptul ca pe <a href="'.$siteurl_clean.'">site-ul nostru</a> am publicat '.$nr_property.' oferte noi, conform cerintelor dvs!<br>Mai jos gasiti lista acestora.<br><br>Va dorim o zi buna!';
$after_properties = '<br><br><div style="font-family: sans-serif; background: #f7f7f7; border: 1px solid #eee; padding: 5px 25px; border-radius: 10px" class="speech"><p style="font-family: sans-serif">Daca doriti, va puteti dezabona de la acest newsletter cu un simplu <a href="'.$siteurl_clean.'dezabonare_newsletter_auto.htm?mail='.$n['mail'].'">click aici</a>.</p></div>';
send_mail_property_query($q_property, $n['mail'], $subject, $message, $after_properties);
#send_mail_property_query($q_property, '[email protected]', $subject, $message, $after_properties);
# echo "send_mail_property_query($q_property, '[email protected]', $subject, $message, $after_properties);";
}
#echo $q_property;
mysql_query("update newsletter_auto set last_send='".strtotime(date('d.m.Y').' 00:01')."' where mail='".$n['mail']."' ");
}
###################################################
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo '<br><br>TOTAL TIME: '.$total_time.' seconds. ';
###################################################
-
- Collaborator
- Posts: 783
- Joined: Mon May 11, 2015 8:43 am
- Contact:
- Os: CentOS 6x
- Web: apache + nginx
Re: Problem with the cronjob - The cronjob is not sending newsletters
Are you sure that the queries are correct? And there is data in your database?