If i do this in Laravel 5.1
Route::get('test_email', function(){
Mail::raw(
"",
function ($mail) {
$mail->from('info#test.com');
$mail->to('test#test.com', 'test');
}
);
});
The email is sent to MAIL_TO_ADDRESS set into .env. It ignore the to value.
Why?
Please try this:
Mail::send('', array(), function($mail) {
$mail->to('example#example.com', 'full_name')->from('example#example.com')->subject('Mail');
});
\Mail::send('view_name', [array of parameters for sending them to view file], function($mail) {
$mail->to('example#example.com', 'full_name')->from('example#example.com')->subject('Mail');
});
You have to use "log" as MAIL_DRIVER.
You can set the above mail configuration in config/mail.php
Mail will be logged to the log file you can open log file at storage/logs and you can see the mail in it.
Related
I'm trying to set up messages delivery status check with twilio. For some reasons twilio statusCallback doesn't fire. Could you please help me to find an error?
Here is a file where I do initialization and send messages:
const Twilio = require('twilio');
const {
TWILIO_ACCOUNT_SID,
TWILIO_AUTH_TOKEN,
TWILIO_PHONE_NUMBER
} = require('config');
const client = new Twilio(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);
module.exports = {
send: (body, phoneNumber) => client.messages.create({
body,
to: phoneNumber,
from: TWILIO_PHONE_NUMBER,
statusCallback: 'http://postb.in/b/XXXXXXXX'
})
.then((message) => {
console.log(message.sid);
return message.sid;
})
};
Here is a test where I call message sending after initialization:
const { expect } = require('chai');
const smsUtility = require('utils/sms');
describe('Sms utility', () => {
it('should send a message and return message sid', (done) => {
const body = 'Body';
const number = '+XXXXXXXXXXX';
smsUtility.send(body, number)
.then((messageSid) => {
expect(typeof messageSid).to.equal('string');
return done();
})
.catch((err) => {
console.log(err);
return done();
});
});
});
I use test credentials, but when I replace it with real twilio credentials, I successfully receive a message, so this part works fine. Also, when I try to ping postb.in url manually (with curl), it also works OK. Only statusCallback doesn't work.
Thanks.
Twilio developer evangelist here.
It looks to me like you have everything set up nicely aside from your Postbin URL.
I noticed you show your URL as http://postb.in/b/XXXXXXXX. But the /b/ version of the URL is the dashboard for your Postbin. Requests to the dashboard won't show up on the dashboard.
Instead, you should use the URL that looks like: http://postb.in/XXXXXXXX. Try that and let me know if it's working.
I am providing the following Payload to admin.messaging().sendToDevice(fcmToken, message);
var message = {
notification: {
title_loc_key: "NOTIFICATION_TITLE",
body_loc_key: "NOTIFICATION_BODY",
body_loc_args: ["Body Arg"],
sound: 'default'
}
};
However this generates the following error:
Messaging payload contains an invalid value for the "notification.body_loc_args" property. Values must be strings.
I don't see how "Body Arg" is not a string. I also tried specifying a string but this also did not work...
Any idea what the problem could be?
Thanks
I'm not sure what version of the Admin SDK is being used, but if the code is on the latest, then only title and body go in the notification object. Other values go under the payload key. Here's an example in the guide. Here is the API reference. Your message variable should look somewhat like this:
var message = {
apns: {
payload: {
aps: {
alert: {
title_loc_key: "NOTIFICATION_TITLE",
body_loc_key: "NOTIFICATION_BODY",
body_loc_args: ["Body Arg"],
sound: 'default'
}
}
}
}
};
If the code doesn't use the latest version of the Admin SDK, I recommend updating.
I use cloud functions to send notifications. It works, but I want collapsible messages. How can I do it? Here is my current function:
exports.sendNotifications = functions.database
.ref("/users/{userId}/data")
.onWrite(event => {
const userId = event.params.userId;
if (!event.data.val()) {
return;
}
const payload = {
notification: {
title: `Hey`,
body: 'It's your turn!'
//icon: receiver.photoURL
}
};
const options = {
collapseKey: 'myturnkey'
};
return admin
.database()
.ref(`users\/${userId}\/data\/notificationkey`)
.once('value')
.then(data => {
console.log('inside key', data.val());
if (data.val()) {
return admin.messaging().sendToDevice(data.val(), payload, options);
}
});
});
I tried "collapseKey" and "collapse_key" in options but none of them works, I still receive notifications every time my function is called, so I get a list of notifications on my iphone whereas I want only one.
EDIT
I also tried the parameter "apns-collapse-id" according to the FCM messages documentation, but when when I try to deploy the functions the console says " apns-collapse-id: 'myturnkey', ^ SyntaxError: Unexpected token -"
Thank you,
Alexandre
You can do this, or manipulate current notifications in other ways, using the registration.getNotifications() API which gives you access to all the currently visible notifications for your web app.
But you need to write this code in your Service-worker
see this documention for merging-notifications
I have read several SO posts about using Mandrill with Meteor.js for email validation, yet I've found a problem no others seem to face.
Ultimately, I want the verified property of a user to be set to true after clicking the email validation url. I am using Mandrill to send customized email templates containing a verification_url. I have the accounts-password and accounts-ui packages added. My code looks like this:
if (Meteor.isServer) {
Meteor.startup(function () {
Mandrill.config({
username: process.env.MANDRILL_API_USER,
key: process.env.MANDRILL_API_KEY
// port: 587, // defaults to 465 for SMTP over TLS
// host: 'smtp.mandrillapp.com', // the SMTP host
// baseUrl: 'https://mandrillapp.com/api/1.0/' // update this in case Mandrill changes its API endpoint URL or version
});
Accounts.config({
sendVerificationEmail: true
});
Accounts.emailTemplates.verifyEmail.html = function (user, url) {
var referralCode = Random.id();
var result;
try {
result = Mandrill.templates.render({
template_name: 'email-verification',
template_content: [],
merge_vars: [
{
name: 'SUBJECT',
content: 'my fancy subject'
},
{ name: 'EMAIL',
content: 'my fancy email'
},
{
name: 'VERIFICATION_URL',
content: 'http://localhost:3000/?ref=' + referralCode
}
]
});
} catch (error) {
console.error('Error while rendering Mandrill template', error);
}
return result.data.html;
};
});
When I create a user the verification email is correctly sent, however when I click the verification link within the email, nothing is done on the server, i.e. I look at my app's MongoDB and see on the user document still have the property verified: false. I've tried to work with onEmailVerificationLink (http://docs.meteor.com/#/full/Accounts-onEmailVerificationLink) but I get an error in the console saying onEmailVerificationLink has already been called, which happens because accounts-ui is apparently calling it for me. How do I do proper email verification in Meteor.js using Mandrill?
Finally figured it out. Instead of the line
content: 'http://localhost:3000/?ref=' + referralCode
I should replace it with
content: url
since Meteor is already creating the validation url for me, and passing it in through the "url" argument of the function. Clearly I didn't need referralCode either
I'm running a sample jQueryMobile app that runs in PhoneGap. The problem is that it doesn't run the getJSON callback to retrieve data, shown below:
$( function()
{
$('#searchButton').click(function()
{
alert("search clicked"); <== this alert works
var url = "http://api.alternativeto.net/software/firefox?callback=?";
$.getJSON(url, function(data) <== this should be, but isn't being called
{
alert("function data called"); <== so this alert doesn't show.
} // end function (data)
); // end getJSON
alert("getJSON call completed"); <== and this alert works
} // end search click.function()
); // end $(
The "search clicked" and "getJSON call completed" alerts both work. The returned JSON I get from entering the url in a browser is valid.
The test code is from this URL:
http://wiki.phonegap.com/w/page/36868306/UI%20Development%20using%20jQueryMobile
Is there anything else I can check?
I don't believe you need the ?callback=? in your url since you can make cross-domain requests from an app.
I have had success with:
$.getJSON('http://google.com/', function (data) {console.log(data);});
..which logged the HTML of Google's homepage.