timed out when trying to connect to different SMTP servers

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

timed out when trying to connect to different SMTP servers

Post by decipher »

Firstly I have to say swiftmailer seems like a very useful package, if I could get it to work.
I would really love some help or feedback on why I cannot use swiftmailer to connect to an outgoing SMTP server.

I keep getting the following error message when trying to connect to bunch of different local SMTP servers:
"Connection to the given MTA failed. The Connection Interface said: Connection timed out"

I used the same host SMTP as where the swiftmailer script is called. (Script is hosted on mweb.co.za and SMPT used is smtp.mweb.co.za)
I have also tried the SMTP server of my local ISP, but get the same error message.

Not sure what to do to solve this issue, i'm trying to learn about mailing but my knowledge is still quite limited.
SendMail works fine with the server but I plan to send thousands of emails and would prefer to use SMTP to do this.
If anyone has any suggestions it would be greatly appreciated.
Thank you.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: timed out when trying to connect to different SMTP serve

Post by Chris Corbyn »

Sounds like your host is blocking traffic, or the remote server is blocking your connection.

Do you have shell access to the server? If so, try this:

Code: Select all

-$  telnet <server-name-here> 25
#wait and see if you get a response now
If you don't have telnet, just try:

Code: Select all

$sock  = fsockopen("server-name", 25, $errno, $errstr, 10);
var_dump($sock);
echo "<br />Error number: $errno";
echo "<br />Error message: $errstr";
Swift does nothing more magical than opening a socket to the remote server :)
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post by decipher »

thanx for the reply.
I unfortunately don't have have shell access to the remote server, but I tried your code and got the following:

bool(false)
Error number: 110
Error message: Connection timed out

i tried using
$sock = fsockopen("smtp.mweb.co.za", 25, $errno, $errstr, 10);
and
$sock = fsockopen("mweb.co.za", 25, $errno, $errstr, 10);

and got the error for both.

I then thought about the returned headers from a returned email I received using the mail() function, and found a different domain:

Received: from mercury.mweb.net ([196.2.16.75] helo=mercury.mweb.co.za)
by remail.mweb.net with esmtp (Exim 4.60)
id 1H4yqy-0003Ci-VF
for <****@****.net>; Thu, 11 Jan 2007 14:16:21 +0200

So I decided to try remail.mweb.net and it seems to be working now.
Thanx a lot for the help!

Is it a good idea to trust this server to send many thousand emails?
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post by decipher »

If i remember correctly, doesn't mail() get routed through the host's default smtp server?
Is there a method to check the default smtp for which the script resides on?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I can't offer that help I'm afraid ;) Your host will be able to tell you what SMTP server to use, although it looks ok to me, they may change things around often.

Usually looking up the MX record of the domain your host runs on will give to the answer, but it's possible to route incoming and outgoing mail via different servers. Bottom line, ask your host :)
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post by decipher »

By my "host", do you mean my ISP's smtp server, or the host where the script is hosted SMTP server?

I tried doing a whois on the domain but it did not give any smtp information, how would i do a MX record?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

decipher wrote:By my "host", do you mean my ISP's smtp server, or the host where the script is hosted SMTP server?

I tried doing a whois on the domain but it did not give any smtp information, how would i do a MX record?
You need a command line tool called "dig". I belive there will be online services that offer dig queries.

I meant the SMTP server of the host your script is on :)
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post by decipher »

Thankyou for all your help, I believe I am finally getting somewhere. :):)

I remember now I would like to ask one last question..
To send large batch emails using SMTP (say 6000), would be better to use cron to send limited emails per batch, or using the anti flood plugin to send all 6000 emaiils?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

decipher wrote:Thankyou for all your help, I believe I am finally getting somewhere. :):)

I remember now I would like to ask one last question..
To send large batch emails using SMTP (say 6000), would be better to use cron to send limited emails per batch, or using the anti flood plugin to send all 6000 emaiils?
Better to use cron. I provided that plugin because some people don't like cron for whatever reason :) However, the plugin can be used in combination with cron for "moderate" numbers of emails (say 400 emails with a 5 second pause after every 50). It's an anti-flood plugin, not a mass-mailing plugin, although it can be used for mass mailing if cron really isn't an option.
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post by decipher »

Sweet, thanx for clearing that up.
I have done a lot of testing with mail() and with my remote server it can take anywhere from 2sec to 64sec to send a batch of 30 emails.
For my test i was simply outputting javascript timeout code to wait 5 sec after sending the 30 mails, and then reload the page..

For the formal mass mailing, i will be using cron, and I wanted to know Is using SMTP a lot faster than mail(). Would it send 50 emails with no attachments fairly quickly?
Can this combination of cron and anti flood plugin be used to send mailings of up to 100 000 emails?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

decipher wrote:Sweet, thanx for clearing that up.
I have done a lot of testing with mail() and with my remote server it can take anywhere from 2sec to 64sec to send a batch of 30 emails.
For my test i was simply outputting javascript timeout code to wait 5 sec after sending the 30 mails, and then reload the page..

For the formal mass mailing, i will be using cron, and I wanted to know Is using SMTP a lot faster than mail(). Would it send 50 emails with no attachments fairly quickly?
Can this combination of cron and anti flood plugin be used to send mailings of up to 100 000 emails?
It varies hugely between linux servers and windows servers. I'll asssume linux.

In which case, your answer is no, mail() will be faster than SMTP since linux server simply pass the mail to a local binary which queues it for sending when the server "gets time" to do it. With SMTP, the receiving server needs to listen to what you tell it and respond appropriately... it's like the two computers have a short conversation.

Advantages of Swift?

* Messages are far less likely to be blocked as spam
* The fact it uses SMTP allows to get know if the server really is sending the email, not just sticking it on the mail queue
* Some hosts restrict the number of emails you send per-hour via mail()
* Windows machine run slower with mail() - non-persistent connections yadda yadda yadda

Using the sendmail connection will be faster, and using the "NativeMail" connection will be comparable with the speed of mail() on either system.
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post by decipher »

Linux ofcourse ;)

Okay so using sendmail will be faster but is SMTP more reliable?
Would be a better option using sendmail with anti flood plugin and cron compared to SMTP?

Does the sendmail connection use a persistant connection compared to just looping through recipients and mail() 'ing it off?
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post by decipher »

i've just found out that using

Code: Select all

new Swift_Connection_SMTP(SWIFT_AUTO_DETECT);
will use php.ini SMTP setting, which in my case is localhost, which i assume defaults to the servers assigned smtp server.
This would have solved my problem from first post, doh! 8O

Would appreciate if you had the time to answer my previous post.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

decipher wrote:Linux ofcourse ;)

Okay so using sendmail will be faster but is SMTP more reliable?
Would be a better option using sendmail with anti flood plugin and cron compared to SMTP?

Does the sendmail connection use a persistant connection compared to just looping through recipients and mail() 'ing it off?
Using Sendmail "appears" faster because the mail gets whacked onto a queue locally. However, it still takes the same amount of time when it finally leaves the queue because currently the only standard way to deliver email is via the SMTP protocol, so the mail inevitably goes through the SMTP process at a later time. Your recipients will not see the mail any faster -- in fact, probably slower, but your script will end sooner. What do you want? :)

The sendmail connection in Swift uses a persistent connection yes. It also talks in SMTP mode the a local binary on the server (not over TCP) rather than doing what mail() does and simply throwing emails at it with barely any feedback. This means if Sendmail rejects any recipients you can find out about it.... with mail() that's not true.

I'm speaking entire in a linux environment here; Windows uses a totally different mechanism for mail().

SMTP is more reliable if you want to know what happened with the emails you sent, but the Sendmail connection in Swift puts Sendmail into a special mode which speaks SMTP anyway.

If you use the SMTP connection you spread the work across two servers and therefore lower the load, but you have to account for the extra time used by network traffic.... but don't be fooled that the emails are taking longer to send because of this; the reality is that you're just watching them leave the queue sooner.
decipher
Forum Commoner
Posts: 38
Joined: Mon Mar 13, 2006 6:27 am
Location: south africa

Post by decipher »

I did read somewhere that even mail() function uses smtp so thanx for clearing that up.. SMTP for outgoing mail.. I'm getting there! ;)

Okay so I have decided to use the sendmail instead, combined with anti-flood plugin and cron.
I guess the best way to find out which is best is to test and see for myself.. If sendmail is putting too much load on the server i will resort to straight SMTP connection.. I have a 4000 emails database but wish to eventually find a method to send up to 100 000.

Thanx for all the help man :)
Post Reply