What is my mistake when i config the CRON? I want send newsletter automatically:
in the init plugin function:
elgg_register_plugin_hook_handler('cron', 'minute', 'cronmail_cron');
and
function cronmail_cron($hook, $entity_type, $returnvalue, $params){
$usuarios = getUsuarios();if(!empty($usuarios) OR !isset($usuarios)){
foreach ($usuarios as $usuario) {
$objetivo = getObjetivo($usuario->guid);
// $ideias = getIdeiaPorObjetivo($objetivo);
$ideias = get_entities_by_relationship_count('member', true, "", "", 0, 5, false,"",false);$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'myhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myuserr'; // SMTP username
$mail->Password = 'mypass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted$mail->From = 'teste';
$mail->FromName = 'teste';$mail->addAddress($usuario->email); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML$mail->Subject = 'teste';
$mail->Body = utf8_decode(elgg_view('ideias', array('ideias' => $ideias)));if(!$mail->send()) {
echo "Ops... <br/>Um erro ocorreu ao enviar sua mensagem.<br/> Tente novamente mais tarde.";
//echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Obrigado por nos contatar.<br/> Você receberá uma resposta em breve!';
}
}
}
}
That code works when i call in a action but i need it automacally. How i do it??
I read the docs:
http://docs.elgg.org/wiki/CronPlugins
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Paweł Sroka@srokap
Paweł Sroka - 0 likes
- Marcelo de Andrade@marceloandrade0201
Marcelo de Andrade - 0 likes
- Paweł Sroka@srokap
Paweł Sroka - 0 likes
- Marcelo de Andrade@marceloandrade0201
Marcelo de Andrade - 0 likes
- Paweł Sroka@srokap
Paweł Sroka - 0 likes
- Marcelo de Andrade@marceloandrade0201
Marcelo de Andrade - 0 likes
- Marcelo de Andrade@marceloandrade0201
Marcelo de Andrade - 0 likes
- Matt Beckett@Beck24
Matt Beckett - 0 likes
- Marcelo de Andrade@marceloandrade0201
Marcelo de Andrade - 0 likes
You must log in to post replies.Did you actually configured cron daemon in your system?
@Pawel Sroka No! The Elgg core need configure anymore items?
Of course. Every PHP framework does.
Have a look at sample cron config here: https://github.com/Elgg/Elgg/blob/1.9/docs/examples/crontab.example and some docs about installing it http://docs.elgg.org/wiki/Cron
I'd suggest to read about cron itself as well: https://en.wikipedia.org/wiki/Cron
@Pawel Sroka Thank you
I config the cron jobs in CPANEL: * / * / * / * / * - http://www.myelgg.com/cron/minute
Still not working, Whats my mistake?
You should have option in cpanel to send cron output to your email. Enable it for debugging.
I assume domain you've inserted is fake.
Whatever this weird syntax is, I'd rather expect it to be something similar to: * / * / * / * / * - /usr/bin/wget http://www.myelgg.com/cron/minute
You're running shell command. It won't magically guess what do you want to do with url. Note that my example is system-specific, you might have different path on your system.
Thank you so much, Sroka! Works fine!
@Sroka
There is some form the two functions cron/weekly, be the calling in diferent dates?
in the cron/cpanel is possible, but how i calling diferentes functions?
use the daily cron and check in your handler for the day using the php date() function
only run the function if the daily cron is triggering on the specific day you want
Thanks a lot, @Matt @Sroka