I just build a simple system information. I want to send email automatically to user every Monday. How to send email automatically in Laravel 5, is there a tool that can solve my problem?
#bogdan this is my code
Controller
public function send_email(){
$date = getdate();
$date_now = date('Y-m-d',strtotime('now'));
$date_exp = date('Y-m-d', strtotime('+6 day'));
$certificate_data = Certificate::where('expired_date', '<=', $date_exp)->where('expired_date', '>=', $date_now)->get();
foreach($certificate_data as $key => $certificate){
$student_data = $certificate->student;
$student_company = Student::find($student_data->id)->company;
$data = ['com_nama' => $student_company->name, 'nama' => $student_data->name, 'judul'=>$certificate->title,'exp_date'=>$certificate->expired_date];
$path_file = Config::get('custom_path.certificates').'/'. $certificate->image;
$test = Mail::send('emails.notification', $data, function($m) use($student_company,$path_file,$student_data,$certificate){
$m->to($student_company->email);
$m->subject('Pemberitahuan Waktu Kadaluarsa Sertifikat');
$m->attach($path_file, ['as' => $student_data->name.'-'.$certificate->title]);
});
}
}
here the error
You can make use of Artisan Scheduling. In your case something like this should do:
$schedule->call(function()
{
// Send emails here
})->mondays();
Related
I want to get 28,000 records data from external API.
For this, I use nusoap_client. However, when I test it I don't get any data and I don't get any error.
This is my function:
public function get_all(){
$url = "http://xxx.xx.x.xx:xxx/services/Pending?wsdl";
$client = new \nusoap_client($url, 'wsdl');
$pDate = isset($_GET["Date"]) ? $_GET["Date"] : '26/2/2017 01:01:01';
$operation = 'getPendingData';
$param1 = array(
'Date' => $Date,
);
$result = $client->call($operation, $param1);
print_r($result);
exit();
}
In the API I must get data starting from 26/02/2017 01:01:01. When I test it I don't get any data. When I changed date to 27/02/2017 01:01:01 I got 759 records data.
How to fix this?
in there i have been create function for send an email, here my code like this :
$row=DB::table('orders')
->join("cms_members","cms_members.id","=","orders.id_cms_members")
->select("orders.*","cms_members.email as email","cms_members.name as name","cms_members.phone as phone")
->where('orders.id',$id_order)
->first();
$datas = array(
'name' => 'test',
'detail'=> 'test',
'sender' => 'adamprojo#gmail.com'
);
$customPaper = array(0,0,800,800);
$pdf = PDF::loadView('testing', $data)->setPaper($customPaper);
Mail::send('emails.temp', $datas, function($message) use($pdf)
{
$message->from("no-reply#crocodic.net","Invoice HOP Daily rent Orders");
$message->to($row->email)->subject('Invoice');
$message->attachData($pdf->output(), "invoice.pdf");
});
here my problem when ever i want to send an email i get response
Address in mailbox given does not comply with RFC 2822, 3.6.2.
but if i try to print the email its give me the email address. what should i do ?
Kindly, can someone give me any solution for mentioned problem?
This will be your code:
$row=DB::table('orders')
->join("cms_members","cms_members.id","=","orders.id_cms_members")
->select("orders.*","cms_members.email as email","cms_members.name as name","cms_members.phone as phone")
->where('orders.id',$id_order)
->first();
$datas = array(
'name' => 'test',
'detail'=> 'test',
'sender' => 'adamprojo#gmail.com'
);
$customPaper = array(0,0,800,800);
$pdf = PDF::loadView('testing', $data)->setPaper($customPaper);
Mail::send('emails.temp', $datas, function($message) use($pdf, $row)
{
$message->from("no-reply#crocodic.net","Invoice HOP Daily rent Orders");
$message->to($row->email)->subject('Invoice');
$message->attachData($pdf->output(), "invoice.pdf");
});
You need to set use($pdf, $row) by the Mail::send(), this will get the $row data that you use in the $message->to().
Hope this works!
I am having some trouble implementing the pushwoosh class http://astutech.github.io/PushWooshPHPLibrary/index.html. I have everything set up but i am getting an error with the array from the class.
This is the code i provied to the class:
<?php
require '../core/init.php';
//get values from the clientside
$sendID = $_POST['sendID'];
$memID = $_POST['memID'];
//get sender name
$qry = $users->userdata($memID);
$sendName = $qry['name'];
//get receiving token
$qry2 = $users->getTokenForPush($sendID);
$deviceToken = $qry2['token'];
//i have testet that $deviceToken actually returns the $deviceToken so thats not the problem
//this is the array that the php class requires.
$pushArray = array(
'content' => 'New message from ' . $sendName,
'devices' => $deviceToken,
);
$push->createMessage($pushArray, 'now', null);
?>
And this is the actually code for the createMessage() method
public function createMessage(array $pushes, $sendDate = 'now', $link = null,
$ios_badges = 1)
{
// Get the config settings
$config = $this->config;
// Store the message data
$data = array(
'application' => $config['application'],
'username' => $config['username'],
'password' => $config['password']
);
// Loop through each push and add them to the notifications array
foreach ($pushes as $push) {
$pushData = array(
'send_date' => $sendDate,
'content' => $push['content'],
'ios_badges' => $ios_badges
);
// If a list of devices is specified, add that to the push data
if (array_key_exists('devices', $push)) {
$pushData['devices'] = $push['devices'];
}
// If a link is specified, add that to the push data
if ($link) {
$pushData['link'] = $link;
}
$data['notifications'][] = $pushData;
}
// Send the message
$response = $this->pwCall('createMessage', $data);
// Return a value
return $response;
}
}
Is there a bright mind out there that can tell me whats wrong?
If I understand, your are trying to if your are currently reading the devices sub-array. You should try this:
foreach ($pushes as $key => $push) {
...
// If a list of devices is specified, add that to the push data
if ($key == 'devices') {
$pushData['devices'] = $push['devices'];
}
You iterate over $pushes, which is array('content' => ..., 'devices' => ...). You will first have $key = content, the $key = 'devices'.
It looks like the createMessage function expects an array of messages, but you are passing in one message directly. Try this instead:
$push->createMessage(array($pushArray), 'now', null);
The class is expecting an array of arrays; you are just providing an array.
You could do something like this
//this is the array that the php class requires.
$pushArrayData = array(
'content' => 'New message from ' . $sendName,
'devices' => $deviceToken,
);
$pushArray[] = $pushArrayData
Will you ever want to handle multiple messages? It makes a difference in how I would do it.
i don't understand how send one email for all users, i do it this in my controller :
// Init
$data = $this->request->data['Email'];
$d = array(
'subject' => $data['subject'],
'message' => $data['message']
);
// QUERY
$all = $this->Spoutnik->find('all', array(
'conditions' => array(
'Spoutnik.role >=' => '1'
),
'fields' => array('Spoutnik.email')
));
$this->set(compact('all'));
// list
$bcc = '';
foreach ($all as $user) {
$bcc .= $user['Spoutnik']['email'].',';
}
// MAIL
App::uses('CakeEmail', 'Network/Email');
$CakeEmail = new CakeEmail('default');
$website_short_name = Configure::read('website.short_name');
$CakeEmail->bcc("$bcc");
$CakeEmail->subject(''.$website_short_name.' :: '.$d['subject'].'');
$CakeEmail->viewVars(array(
'message' => (''.$d['message'].'')
));
$CakeEmail->emailFormat('html');
$CakeEmail->template('message_direct');
// final
$CakeEmail->send();
But i have error "no valid mail" , and after the liste of user's mail
what is wrong in my code ?
Couple of things I've noticed at a quick glance...
foreach ($all as $user) {
$bcc .= $user['Spoutnik']['email'].',';
}
In that code, you're adding a comma after every email, so at the end of your string you'll have a comma. Try this:
$e = 0;
foreach ($all as $user) {
if($e > 0) $bcc .= ',';
$bcc .= $user['Spoutnik']['email'];
$e++;
}
--edit-- good point Deepak, Cake's documentation suggests you give BCC an array. It's easier and more efficient to produce so do that.
Second, $CakeEmail->bcc("$bcc"); doesn't need the quotes. It should work fine with them, but I've seen Cake do some pretty weird things... Try taking them out:
$CakeEmail->bcc($bcc);
Third, you're setting all those emails to BCC which is fine, but I can't see a to address. If you want to send out to a lot of email address without them seeing each other, you still need to send the email to somewhere, even if its noreply#yourdomain.com. Add a to address in before you send:
$CakeEmail->to('noreply#yourdomain.com');
I will just use the addBcc function of CakeEmail and modify the loop:
App::uses('CakeEmail', 'Network/Email');
$CakeEmail = new CakeEmail('default');
// list
foreach ($all as $user) {
$CakeEmail->addBcc($user['Spoutnik']['email']);
}
$website_short_name = Configure::read('website.short_name');
$CakeEmail->subject(''.$website_short_name.' :: '.$d['subject'].'');
$CakeEmail->viewVars(array(
'message' => (''.$d['message'].'')
));
Try changing your $bcc block to this:
// list
$bcc = array();
foreach ($all as $user) {
$bcc[]= $user['Spoutnik']['email'];
}
Also refer to CakeEmail Documentation
I am trying to make a privet application with php on zend google data api. I need to create events from a script. The problem I am facing is, I cannot add guest/attendee/participant from the script on the event. Actually I couldn't find the correct parameter.
The function I am using:
function createEvent ($client, $title = 'Tennis with Beth',
$desc='Meet for a quick lesson', $where = 'On the courts',
$startDate = '2008-01-20', $startTime = '10:00',
$endDate = '2008-01-20', $endTime = '11:00', $tzOffset = '-08')
{
$gdataCal = new Zend_Gdata_Calendar($client);
$newEvent = $gdataCal->newEventEntry();
$newEvent->title = $gdataCal->newTitle($title);
$newEvent->where = array($gdataCal->newWhere($where));
$newEvent->content = $gdataCal->newContent("$desc");
$when = $gdataCal->newWhen();
$when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
$when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
$newEvent->when = array($when);
// Upload the event to the calendar server
// A copy of the event as it is recorded on the server is returned
$createdEvent = $gdataCal->insertEvent($newEvent);
return $createdEvent->id->text;
}
I tried to add it by $newEvent->guests,$newEvent->attendees, $newEvent->Participants.
Anybody know the way?
Also it will be helpful if you can also tell me how to choose a calendar with id instead of the primary calendar. Thanks in advance.
You can set this using the following code :-
$who = $gcal->newwho();
$who->setEmail('myEm...#myDomain.com');
$event->setWho(array($who));