I'm trying to get a simple email confirmation through sendgrid working. I've been trying the php examples, just cutting and pasting and substituting the email addresses username, password, etc. I've installed Swift 4.1.1 and the SmtpAPIHeaderFile, but I cannot seem to get it to work. I get the following error. If you have any ideas, please let me know:
Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to smtp.sendgrid.net:25 (Connection refused) in /home1/twelvebl/public_html/Sponto/lib/classes/Swift/Transport/StreamBuffer.php on line 271
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.sendgrid.net [Connection refused #111]' in /home1/twelvebl/public_html/Sponto/lib/classes/Swift/Transport/StreamBuffer.php:273 Stack trace: #0 /home1/twelvebl/public_html/Sponto/lib/classes/Swift/Transport/StreamBuffer.php(66): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home1/twelvebl/public_html/Sponto/lib/classes/Swift/Transport/AbstractSmtpTransport.php(116): Swift_Transport_StreamBuffer->initialize(Array) #2 /home1/twelvebl/public_html/Sponto/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #3 /home1/twelvebl/public_html/Sponto/test.php(102): Swift_Mailer->send(Object(Swift_Message), Array) #4 {main} thrown in /home1/twelvebl/public_html/Sponto/lib/classes/Swift/Transport/StreamBuffer.php on line 273
Help get this topic noticed by sharing it on
Twitter,
Facebook, or email.
Twitter,
Facebook, or email.
-
Hi Levi,
It looks like you're trying to connect to smtp.sendgrid.net on port 25. Please try setting your port to 587, like so:
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
Let me know how that goes... we'll get it figured out!
Brandon West
Developer Evangelist -
-
Thanks for your suggestion. I tried this and now get a connection timed out #110 error. Any other ideas?
-
-
Do you mind posting your code? It could be a number of things, like a firewall blocking a port or trying to use SSL on that port (our SSL port is 465).
-
-
I'm using it from a standard bluehost hosting account. No firewall as far as I know. Here's the source (note I substituted "[redacted]" for personal info:
addTo($toList);
// Specify that this is an initial contact message
$hdr->setCategory("initial");
// You can optionally setup individual filters here, in this example, we have enabled the footer filter
// The subject of your email
$subject = 'Example SendGrid Email';
// Where is this message coming from. For example, this message can be from support@yourcompany.com, info@yourcompany.com
$from = array('info@[redacted]' => '[redacted]');
// If you do not specify a sender list above, you can specifiy the user here. If a sender list IS specified above
// This email address becomes irrelevant.
$to = array('[redacted]'=>'[redacted]');
# Create the body of the message (a plain-text and an HTML version).
# text is your plain-text email
# html is your html version of the email
# if the reciever is able to view html emails then only the html
# email will be displayed
/*
* Note the variable substitution here =)
*/
$text = <<<<
Hello -name-,
Thank you for your interest in our products. We have set up an appointment
to call you at -time- EST to discuss your needs in more detail.
Regards,
FredHow are you?
EOM;
// Your SendGrid account credentials
$username = '[redacted]';
$password = '[redacted]';
// Create new swift connection and authenticate
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport ->setUsername($username);
$transport ->setPassword($password);
$swift = Swift_Mailer::newInstance($transport);
// Create a message (subject)
$message = new Swift_Message($subject);
// add SMTPAPI header to the message
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $hdr->asJSON());
// 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
// If we specify the names in the X-SMTPAPI header, then this will always be 1.
echo 'Message sent out to '.$recipients.' users';
}
// something went wrong =(
else
{
echo "Something went wrong - ";
print_r($failures);
} -
-
-
-
Hi Levi,
Your code looks good so I've done a bit of searching and I think the problem may indeed be blocked ports on bluehost, for example: http://drupal.org/node/458044 and http://blog.codelab.co.nz/2010/01/12/...
If you'd like you can open a ticket with our support team at support.sendgrid.com so they can get your username and take a look at your account and see if anything is looking strange, but you may need to contact bluehost as well.
Please let me know if that helps! -
-
Thanks, I checked with bluehost. Indeed they block that port. Here's their response: "Thank you for contacting us. Yes, port 587, as well as the other SMTP ports like 25, 26 and 465. We do not allow outbound SMTP connections. To send emails, you must use our SMTP (localhost)."
Given this, any other workaround other than switching hosts? If a new host is necessary, can you recommend any that have similar hosting packages to bluehost? Thanks much,
Levi -
-
Our suggestion to you is to definitely try signing with another hoster.
Rackspace and Godaddy are a couple that should support what is needed for SMTP.
Thanks for your time and patience.-
Hi Brad, I'm using godaddy hosting and with both ports 25 and 587 I have the same problem as described by Levi. I also just took the code from the PHP example section on sendgrid website.
I can't seem to find anything on the Godaddy forums on how to get this resolved or how to open these ports up if they are blocked.
Would you be able to help me with next steps.
Much appreciated.
Freek -
-
Having same issue as Freek on Godaddy now. Any ideas?
-
-
-
-
-
Hello ,
I hope you are doing good , I am developer and I am using Cpanel HOST SERVER and i got same issue , before i was using PORT 587 then i got error then i change the port 25 but still i got error , please help me , my client too much wooried and asking me again and again to fix this issue ,
If you need more details on this issue then please let me know i will reply you quickly ,
Waiting for your quick and positive response , thanks in advance.. -
-
hello, i have same problem plzzz help me.
i used swiftmailer and phpmailer both worked fine on local ubuntu server but when my client run d code on remote site getting same error..i dont know which host server he is using...plzzzzzzzz help me my boss will fire me -
-
I'm also having the same problem with Godaddy and Sendgrid. At first I tried using their Curl version of the emailer which works on godaddy. The problem with Curl is that when I configure the php5.ini file with max_execution_time=120, Curl becomes unavailable. So, I tried looking at alternative email code. I ended up trying Swift, but I get the same error you guys are getting. I'm so frustrated now and hope someone knows the answer to this problem.
-
-
Same problem here with GoDaddy. Why is nobody answering this thread?
-
-
Any updates to this issue. I have the same problem!!! and clearly want to use SendGrid!
-
-
Same problem, bluehost + sendgrid not working, but works fine in my test sandbox. (sinohosting.net in case any of you were interested - note I'm not speaking to their quality in general, but emails do seem to get through. ) It's probably a competitive issue, couched as a spam-reputation protecting issue as the hosting companeis would likely defend themselves. The solution is a business solution, not technical: Identify (smaller) hosting companies that don't offer their own white-labeled smtp solution, and then continue on connecting through Sendgrid. Sendgrid, being devoted to the purpose, will probably do a better job of reputation protecting, not to mention analytics, etc. than the large hosting companies.
-
-
-
-
I'm using your SendGrid's php sample code and am getting the #111 error.
I've tried all the recommended ports (25, 2525, 587, and 465).
I use Godaddy.com hosting.
It looks like we all need a solution!
So, what is the solution, SendGrid? -
-
I switched over to AWS using Bitnami and everything works great now!
-
Loading Profile...




EMPLOYEE


