2
votes

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 !

5
Please contact the vendor of the library for support questions. - hakre

5 Answers

3
votes

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('[email protected]' => 'John Doe'))
  ->setTo(array('[email protected]', '[email protected]' => 'A name'))
  ->setBody('Here is the message itself')
  ;

//Send the message
$numSent = $mailer->send($message);

printf("Sent %d messages\n", $numSent);
5
votes

(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

2
votes

two resons:

  1. you may have the authentification data wrong

  2. your account might still be provisioned, so you must wait a bit for it to be fully activated

so

Your account is still being provisioned, you may not be able to send emails.

0
votes

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.

0
votes

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 ^^