问题
I'm trying to send mails via sendgrid, here my code :
// Setup Swift mailer parameters
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 25);
$transport->setUsername($username);
$transport->setPassword($password);
$swift = Swift_Mailer::newInstance($transport);
// Create a message (subject)
$message = new Swift_Message($subject);
// attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
// send message
if ($recipients = $swift->send($message, $failures))
{
// This will let us know how many users received this message
echo 'Message sent out to '.$recipients.' users';exit;
}
I got this error : Swift_TransportException
Expected response code 250 but got code "", with message ""
...\swiftMailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php(422)
please help me !
回答1:
Try to send the message in one line to see if that works or returns another error. If it returns an error, it's probably a server or authentication issue.
$result = $swift->send($message);
If that works, you could try the code below and if it works tweak it so it shows your recipients instead of failures.
if (!$swift->send($message, $failures))
{
echo "Failures:";
print_r($failures);
}
Other than that, check if all variables are not empty.
For more examples see: http://swiftmailer.org/docs/sending.html#quick-reference-for-sending-a-message
UPDATE
Sendmail code:
//Create the Transport
$transport = Swift_MailTransport::newInstance();
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Create a message
$message = Swift_Message::newInstance('Subject')
->setFrom(array('john@doe.com' => 'John Doe'))
->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
->setBody('Here is the message itself')
;
//Send the message
$numSent = $mailer->send($message);
printf("Sent %d messages\n", $numSent);
回答2:
(full disclosure: I work at SendGrid as a web developer)
We recently released a new PHP library which may solve some of these problems. We still use Swift but if I recall, the library sets that stuff up for you now, making it a little easier to get rolling.
Don't hesitate to contact us for help, too!
http://github.com/sendgrid/sendgrid-php
回答3:
two resons:
you may have the authentification data wrong
your account might still be provisioned, so you must wait a bit for it to be fully activated
so
check all the autentification data from app/config/mail.php to match with the data from https://sendgrid.com/docs/Integrate/index.html
check also not the have a top message/notification on your sendgrid account like:
Your account is still being provisioned, you may not be able to send emails.
回答4:
I'm just having the same error message with my Symfony 2 config for sendgrid. Hope you've seen this manual: http://docs.sendgrid.com/documentation/get-started/integrate/examples/symfony-example-using-smtp/
Try changing port to 587. Let me know it works.
回答5:
Maybe you where just too fast? I'm facing the same problem after kickstarting with sendgrid and now with the web-api, i got the real error back "account disabled"...
I did not read the full text after first login - they will review first the account until it gets activated... ok, so i wait ^^
来源:https://stackoverflow.com/questions/8725365/send-mails-via-sendgrid