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!
Related
We are attempting to send an email to multiple recipients using the Mailgun PHP API.
We are running MG PHP lib version 2.8.1.
Our code does the following:
note: email address and domain changed for privacy reasons
log_debugger('g1', 'g1');
$params = array(
'from' => $msg_org . " <" . EMAIL_SENDER . ">",
'to' => array('joe#gmail.com'),
'subject' => 'Hey %recipient.first%',
'text' => 'If you wish to unsubscribe, click http://example.com/unsubscribe/%recipient.id%',
'recipient-variables' => '{"joe#gmail.com": {"first":"Joe", "id":1}}'
);
log_debugger('g1', 'g2');
# Make the call to the client.
$mgresult = $mgClient->messages()->send(MAILGUN_DOMAIN, $params);
log_debugger('g1', 'g3');
// if the email was accepted by Mailgun then indicate the member message was delivered
if ($mgresult->http_response_code >= 200 && $mgresult->http_response_code < 300) {
log_debugger('mgr', $mgresult->http_response_code);
// else the email was not accepted by mailgun so indicate the member message failed to be delivered
} else {
log_debugger('g1', 'g4');
}
The call is successfully getting to MG, but we are not getting any return from MG. We have been sending to MG successfully for sometime and now we are attempting to send to multiple email addresses at one time. Below is the data we are passing in as recorded by our debug log.
2020-08-14 12:47:01 g1
2020-08-14 12:47:01 g1
2020-08-14 12:47:01 g1
2020-08-14 12:47:01 g2
Here is the MG documentation - Notice the error: messages()-send should be messages()->send
require 'vendor/autoload.php';
use Mailgun\Mailgun;
// Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = "YOUR_DOMAIN_NAME";
$params = array(
'from' => 'Excited User <YOU#YOUR_DOMAIN_NAME>',
'to' => array('bob#example.com, alice#example.com'),
'subject' => 'Hey %recipient.first%',
'text' => 'If you wish to unsubscribe, click http://example.com/unsubscribe/%recipient.id%',
'recipient-variables' => '{"bob#example.com": {"first":"Bob", "id":1},
"alice#example.com": {"first":"Alice", "id": 2}}'
);
// Make the call to the client.
$result = $mgClient->messages()-send($domain, $params);
Any help getting this to work would be greatly appreciated. Logged a ticket with MG, but no reply as of yet.
Method documented by MG for sending message is not quite correct. I had to change the call from:
$mgresult = $mailgun_client->messages()->send(MAILGUN_DOMAIN, array(
to:
$mgresult = $mailgun_client->sendMessage(MAILGUN_DOMAIN, array(
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();
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 have a script which should scrap selected email from the inbox. Everything works except BODY. Subject, date, sender and etc.. were scraped without problems but the body were returned like this:
VG9kYXkncyBGcmVlIGFuZCBCYXJnYWluIEJvb2tzCgpVcGRhdGUgUHJlZmVyZW5jZXM6ICBodHRw
Oi8vd3d3LmJvb2tnb3JpbGxhLmNvbS9wcmVmZXJlbmNlcz9oPTZjNTgxNDEyYjkzMTdiMWZlNjc1
ZDcwNDFjODJhYTc5Ckludml0ZSBGcmllbmRzOiBodHRwOi8vd3d3LmJvb2tnb3JpbGxhLmNvbS9p
bnZpdGU/aD02YzU4MTQxMmI5MzE3YjFmZTY3NWQ3MDQxYzgyYWE3OQpVbnN1YnNjcmliZTogaHR0
cDovL3d3dy5ib29rZ29yaWxsYS5jb20vdW5zdWJzY3JpYmU/aD02YzU4MTQxMmI5MzE3YjFmZTY3
NWQ3MDQxYzgyYWE3OQoKQWxsIHByaWNlcyB3ZXJlIHZlcmlmaWVkIGJ5IEJvb2tHb3JpbGxhIHBy
aW9yIHRvIHRoaXMgZW1haWwgYmVpbmcgc2VudCwgYnV0IHByaWNlcyBtYXkgY2hhbmdlIHdpdGhv
dXQgbm90aWNlIHNvIHBsZWFzZSB2ZXJpZnkgdGhhdCB0aGUgYm9vayBpcyBzdGlsbCBmcmVlIG9y
IGJhcmdhaW4gcHJpY2VkIGJlZm9yZSBj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E5vdw0KaHR0cDovL3d3dy5ib29rZ29yaWxsYS5jb20vbGluaz9sPWh0dHAlM0ElMkYlMkZ
And I have no idea why is it? This is a code I'm using:
$inbox_details = $this->email_main->getInboxDetails($data['inbox_id']); // select inbox data by inbox id
$message_id = $inbox_details['last_sended_email_id'] + 1;
$imap = imap_open('{'. $data['inbox_data']['inbox_server'] .'}INBOX', ''. $data['inbox_data']['inbox_email'] .'', ''. $data['inbox_data']['inbox_password'] .'');
if (!$imap)
$this->email_main->insertError(imap_last_error(), $data['inbox_data']['id']);
$header = imap_header($imap, $message_id);
$message = array(
'subject' => $header->subject,
'fromname' => $header->fromaddress,
'fromaddress' => $header->from[0]->mailbox.'#'.$header->from[0]->host,
'toaddress' => $header->toaddress,
'date' => $header->date,
'timestamp' => $header->udate,
'body' => imap_qprint(imap_fetchbody($imap, $message_id, 2)), // $message_id = 1
);
any ideas folks?
Your content is encoded in base64.
base64_decode($content);
Will decode it :)
Edit:
Decoded with http://www.base64decode.org/ to get 'Today's Free and Bargain Books'
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