Closed wernight closed 8 years ago
Here is the $email->toWebFormat()
generated:
from
: do-not-reply@example.com
fromname
: Foo's Example
x-smtpapi
: {}Thanks for letting us know. I've added this to our backlog.
Could you provide the relevant code snippet?
<?php
require('vendor/autoload.php');
$email = new \SendGrid\Email();
$email
->addTo('example@example.com', 'Foo Bar')
->setFrom('example@example.com')
->setSubject('test')
->setText('test');
$sendgrid = new \SendGrid(\file_get_contents('/mnt/sendgrid/api-key'));
$sendgrid->send($email);
$ php snippet.php
Fatal error: Uncaught exception 'SendGrid\Exception' with message '{"errors":["Empty from email address (required)"],"message":"error"}' in /srv/vendor/sendgrid/sendgrid/lib/SendGrid.php:120
Stack trace:
#0 /srv/snippet.php(12): SendGrid->send(Object(SendGrid\Email))
#1 {main}
thrown in /srv/vendor/sendgrid/sendgrid/lib/SendGrid.php on line 120
Note:
example@example.com
is just an example as trying different values including whitelabeled domains doesn't change the outcome.php
official image.I did notice that my key has a line return at the end. May be those are not properly handled/escaped.
Without the line return it works (e.g. using \trim()
).
Hmm, I think I had a similar issue, that I fixed with this: https://github.com/sendgrid/php-http-client/blob/master/lib/SendGrid/config.php#L31
Are you saying that once you added the trim() to your api key, it now works?
Yes
However I think it should be fixed as the error really is misleading
Agreed, we'll get that into our backlog. Thanks!
@wernight We have completely revamped our error messaging. Check out our new docs for details: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html
Thanks for your continued support!
@thinkingserious I am getting the same error [Error: Empty from email address (required)] when using nodejs sendgrid module. Here is my code.:
sendgrid.send({ to: 'nitefoodie@gmail.com ', from: 'talk@aircountr.com', subject: 'Report Export', text: 'Please find the attached exported report.', files: [ { filename: '', // required only if file.content is used. contentType: '', // optional cid: '', // optional, used to specify cid for inline content path: '', // url: './file.csv', // == One of these three options is required content: ('' | Buffer) // } ] },function(err, json) { if (err) { return console.error(err); }
console.log(json); res.json("Mail sent successfully"); });
@wizvs Please follow this issue over in the nodejs repo: https://github.com/sendgrid/sendgrid-nodejs/issues/228
I'll be responding to that ticket soon.
I am now having this issue and this link now points to a 404: https://github.com/sendgrid/php-http-client/blob/master/lib/SendGrid/config.php#L31
Hello @ndo360,
Could you please provide some further detail so that I can try and reproduce?
Specifically:
Thank you!
Elmer
@thinkingserious Thank you for replying fast, here is the source code referenced in the error:
[sendgrid.js]
if (json.message !== 'success') { var error = 'sendgrid error'; if (json.errors) { error = json.errors.shift(); } return callback(new Error(error), null); }
[request.js]
// Protect against double callback if (!self._callback && self.callback) { self._callback = self.callback self.callback = function () { if (self._callbackCalled) { return // Print a warning maybe? } self._callbackCalled = true self._callback.apply(self, arguments) }
if (self._json) { try { response.body = JSON.parse(response.body, self._jsonReviver) } catch (e) { debug('invalid JSON received', self.uri.href) } } debug('emitting complete', self.uri.href) if (typeof response.body === 'undefined' && !self._json) { response.body = self.encoding === null ? new Buffer(0) : '' } self.emit('complete', response, response.body) }) }
responseContent.on('end', function (chunk) { self.emit('end', chunk) })
Here is the mailer code: [mailer.js]
`'use strict';
var Config = require.main.require('./server/tools/config'); var SendGrid = require('sendgrid')(Config.SENDGRID_API_KEY);
module.exports = {
sendPasskey: function(name, email, passcode) {
var appName = 'Secret Hitler Online';
var passcodeMail = new SendGrid.Email({
to: email,
from: process.env.SENDGRID_FROM_EMAIL,
subject: passcode,
text: ' ',
html: ' ',
});
passcodeMail.setSubstitutions({
':app': [appName, appName],
':name': [name],
':passcode': [passcode, passcode]
});
passcodeMail.setFilters({
'templates': {
'settings': {
'enable': 1,
'template_id': process.env.SENDGRID_EMAIL_TEMPLATE,
}
}
});
SendGrid.send(passcodeMail, function(err, json) {
if (err) {
console.error('sendPasskey', err);
}
});
},
};`
Also I have attached the screenshot of the error displayed
@ndo360,
What version of the SendGrid Node.js library are you using?
@thinkingserious I manged to fix it as it turned out I missed a step, thanks for everything though!
what step had u missed...please post ur working code!
Hi @Sachin-Suresh,
I'd be happy to try and help. Could you please post the code you are having trouble with and the error message?
Thanks!
With Best Regards,
Elmer
I get the error:
Empty from email address (required)
however this is the email object being sent:Running latest
sendgrid/sendgrid
release (version 4.0.4) which uses latestsendgrid/smtpapi
(version 0.5.0).Similar to issues: