Is there a way to send FCM push notification to all the email address i have in my local database - ionic-framework

Well I'm setting up a database where user details would be stored using ionic as front end and lumen to make API calls. My concern is that can i send a push notification to all the people who are using my application using the email information that is in my database. Is it possible
Following is the code that i am trying to do :
public function send_notification_all(Request $request){
$this->validate($request, [
'title' => 'required|max:30|min:20',
'message' => 'required'
]);
$noti_title = $request->input('title');
$noti_body = $request->input('message');
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20);
$notificationBuilder = new PayloadNotificationBuilder($noti_title);
$notificationBuilder->setBody($noti_body)
->setSound('default');
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);
$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$email = User::pluck('email')->toArray();
$downstreamResponse = FCM::sendTo($email, $option, $notification, $data);
$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();
if($downstreamResponse->numberSuccess() == 0 ){
return $this->errorResponse("unable to send notificaton to all",401);
}else {
return $this->successResponse(['msg' => 'message send successfully','successfull' => $downstreamResponse->numberSuccess(),'failures' => $downstreamResponse->numberFailure()]);
}
}
Just need the opinion that is it possible to do it in this way and do let me know if there is any mistake or the changes that i have to make in my code. Waiting for the Positive response and Guidance

You can't send notifications using their email addresses.
You should save in your Database the fcm_token of every user who registers. I suggest using the following package and reading the docs in it: Laravel-FCM
You should also take care of refreshing the token if the device request so.

Related

Laravel-why admin receives every email message?

I am working on a web application with multiple users, and I have some issue with sending emails.
Sending is working fine, no problems, but the issue is that every mail interaction between visitors and users is sent to admin email address stated in env file. I am using gmail for sending, Laravel 8.
For example, visitor A has sent a message to user B. User B received mail correctly, but also admin received message.
Thanks for help.
Here is my EmailsController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;
class EmailsController extends Controller
{
public function send(Request $request)
{
function sentence_case($string) {
$sentences = explode(" ",$string);
$sentences = array_reverse($sentences);
$new_string = '';
foreach ($sentences as $key => $sentence) {
$new_string = ucfirst(mb_strtolower(trim($sentence)))." ".$new_string;
}
return $new_string;
}
$this->validate($request, [
'ime' => 'required', //visitor name
'email' => 'required', // visitor email address
'poruka' => 'required' //visitor message
]);
$ime = $request->get('ime');
$ime = sentence_case($ime);
$email = $request->get('email');
$poruka = $request->get('poruka');
Mail::send('emails.message', [
'name' => $ime,
'email' => $email,
'comment' => $poruka ],
function ($m) use ($email) {
$m->from($email);
$m->to('usersemail#yahoo.com', 'MyApp')
->subject('Website Contact Form');
});
/* usersemail#yahoo.com is registered user email address different from aplication admin/owner email addres stated in env file, but admin receives this message */
if (Mail::failures()) {
return response()->Fail('Sorry! Please try again latter');
}else{
return back()->with('success', 'Thanks for contacting me, I will get back to you soon!');
}
}
}

Send emails from external mail server in Magento 1.9

I'm trying to get Magento to send transactional emails via our external mail server. I've tried using the SMTP Pro extention, but that didn't work.
I've changed the getMail function in /app/code/core/Mage/Core/Model/Email/Template.php to:
public function getMail()
{
if (is_null($this->_mail)) {
$my_smtp_host = 'xxx';
$my_smtp_port = '587';
$config = array(
'port' => $my_smtp_port, 'auth' => 'login',
'username' => 'xxx',
'password' => 'xxx' );
$transport = new Zend_Mail_Transport_Smtp($my_smtp_host, $config);
Zend_Mail::setDefaultTransport($transport);
$this->_mail = new Zend_Mail('utf-8');
}
return $this->_mail;
}
but the emails are still sending from the local server.
(I know editing core files is bad, this is solely for testing purposes.)
Any ideas on where I'm going wrong?
you may achieve that by setting up a relay between magento server and external mail server. no code changes are necessary if it is an option.

Unable to get Response Parameters in Notification and Success url SOFORT API

public function sofyAction()
{
$args = [ 'config_key' => $this->getConfigKey() ];
$sofy = new Api($args);
$helper = $this->getServiceLocator()->get('ViewHelperManager')->get('ServerUrl');
$successUrl = $helper($this->url()->fromRoute('sofort_response'));
$params = [
'amount' => 1500,
'currency_code' => 'EUR',
'reason' => 'Vouhcer Order',
'success_url' => $successUrl,
'customer_protection' => false,
'notification_url' => 'MY_PRIVATE_RESPONSE_URL',
];
$trans = $sofy->createTransaction($params);
return $this->redirect()->toUrl($trans['payment_url']);
}
How to get response and transaction ID as given it API document in Notification URL and on success URL too , please unable to find any help or guide for it ?
The easiest way is to let Payum do notification related job for you. To do so you either:
have to create manually a notification token using Payum's token factory (I am not sure it is present in the Zend module, it is quite old). Use the token as notification_url. Nothing more. Sofort will send a request to that url and Payum does the rest.
Make sure the token factory is passed to a gateway object and later is injected to capture action object. Leave the notification_url field empty and Payum will generate a new one.
use your own url as notification one and add there all the info you need (as a query string). I wouldn't recommend it since you expose sensitive data and once could try to exploit it.
I solved it this way by appending ?trx=-TRANSACTION- with success and notification url and than in response i recieved Transaction id as parameter and later loaded TransactionData with that transactionId . Payum Token way wasn't working for me ! Obiously had to use its config key to create Payum/Sofort/Api isnstance,
REQUEST:
$args = [ 'config_key' => $sofortConfigKey ];
$sofortPay = new Api($args);
// ?trx=-TRANSACTION- will append transacion ID as response param !
$params = [
'amount' => $coupon['price'],
'currency_code' => $coupon['currency'],
'reason' => $coupon['description'],
'success_url' => $successUrl.'?trx=-TRANSACTION-',
'abort_url' => $abortUrl.'?trx=-TRANSACTION-',
'customer_protection' => false,
'notification_url' => '_URL_'.'?trx=-TRANSACTION-',
];
$transactionParams = $sofortPay->createTransaction($params);
return $this->redirect()->toUrl($transactionParams['payment_url']);
RESPONSE:
$args = [ 'config_key' => $configKey ];
$sofy = new Api( $args );
$transNumber = $this->getRequest()->getQuery('trx');
$fields = $sofy->getTransactionData($transNumber);
Took help from API document. Payum documentation is worst. SOFORT API DOC

Sendgrid change text and style for group unsubscribe links

I'm facing one problem while sending emails with SendGrid. I'm sending normal email with assigning unsubscribe ground id. And when sending email then getting two links Unsubscribe From This List and Manage Email Preferences. Now my requirement is that I want to change these link texts from
Unsubscribe From This List => Unsubscribe
Manage Email Preferences => Update Preferences
And also links are not coming in the bottom of email. I want these after footer texts.
I'm not using marketing emails. Below is the one email screen-shot which I got:-
And below is the code for sending email. I'm using Laravel for sending emails:-
public function sendMail()
{
$status = \Mail::send('emails.demo', ['name' => "testdata"], function($message)
{
$args = [
'asm_group_id' => 3169
];
$message->getHeaders()->addTextHeader('X-SMTPAPI', json_encode($args));
$message->to('test#gmail.com', 'Test User')->subject('This is a demo!');
});
}
Please suggest me if anyone have idea how can I achieve this.
Check this package. https://github.com/s-ichikawa/laravel-sendgrid-driver .
This is the correct format for the above package:
$send = \Mail::send('emails.tests.tests', compact([]),
function (Message $message) use (
$subject, $from_email, $from_name, $to_emails, $to_name ) {
$message->subject($subject)
//->attach($pathToFile)
//->to($to_emails)
->to($to_emails, $to_name)
//->cc($cc_email)
->from($from_email, $from_name)
->embedData([
'asm' => ['group_id' => 123],
],
'sendgrid/x-smtpapi');
});
if you are not using this package then
$status = Mail::send('emails.test', compact('data_var'), function($message)
{
$args = [
'asm_group_id' => 123
];
$message->from('testfrom#gmail.com','from name');
$message->getHeaders()->addTextHeader('X-SMTPAPI', json_encode($args));
$message->to('testto#gmail.com', 'Test User')
->subject('This is a demo!');
});

send email via Magento

I've seen on a few blog articles that this is a common way to send an email in Magento, but I have for the life of me, no idea why this email isnt being sent in 1.10! This is my method:
protected function _emailCode($code, $invoice) {
$order = $invoice->getOrder();
// Transactional Email Template's ID
$templateId = 1;
// Set sender information
$senderName = Mage::getStoreConfig('trans_email/ident_support/name');
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
$sender = array('name' => $senderName,
'email' => $senderEmail);
// Set recepient information
$recepientEmail = $order->getCustomerEmail();
$recepientName = $order->getCustomerName();
// Get Store ID
$storeId = Mage::app()->getStore()->getId();
// Set variables that can be used in email template
$vars = array('voucherCode' => $code);
$translate = Mage::getSingleton('core/translate');
// Send Transactional Email
Mage::getModel('core/email_template')
->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
$translate->setTranslateInline(true);
}
I should note that emails works in other parts of Magento so sendmail is working properly and all that, also all my variables here are defined correctly and not empty when going through this.
Thanks!
Are you sure that transactional email with ID=1 exist?
try setting $templateId='sales_email_order_template'
this is a default template, should fit working script.
Check exception.log also.