开发者

Swift Mailer Error

Im using the following code to send a message:

try
{   
    require_once "lib/Swift.php";
    require_once "lib/Swift/Connection/SMTP.php";
    $smtp =& new Swift_Connection_SMTP("mail.somedomain.net", 587);
    $smtp->setUsername("username");
    $smtp->setpassword("password");
    $swift =& new Swift($smtp);

    //Create the sender from the details we've been given
    $sender =& new Swift_Address($email, $name);
    $message =& new Swift_Message("message title");

    $message->attach(new Swift_Message_Part("Hello"));

    //Try sending the email
    $sent = $swift->send($message, "$myEmail", $sender);
    //Disconnect from SMTP, we're done
    $swift->disconnect();

    if($sent)
    {
        print 'sent';

    }
    else 
    {
        print 'not sent';
    }

}

catch开发者_开发知识库 (Exception $e) 
{
    echo"$e";
}

The issue is that it is working fine on my local server (which my xampp server) but not working when the file is uploaded on the real server.

It throwing this error:

'The SMTP connection failed to start [mail.somedomain.net:587]: fsockopen returned Error Number 110 and Error String 'Connection timed out''

Please what should I do to correct this error. Thanks for reading


Make sure that the smtp server domain is valid. Trying pinging it to confirm a response. You may also try trace route to see if any of the switches are returning slow responses.


$smtp =& new Swift_Connection_SMTP("mail.somedomain.net", 587);

is that '587' the port number to connect to? Any reason you're trying that instead of the normal port 25? Port 587 (submission) is normally used for local users to send mail. Once you're running this script on your remote web server, it's no longer "local", and is most likely firewalled off (or the mail server's not listening to that port on external interfaces).

Try switching to port 25 and see if that helps any.

update:

Connection refused is better than "connection timed out". It means at least that the initial data packet got somewhere and was actively refused. Timed out means things just got dropped silently somewhere en-route.

max_execution_time would only come into play if the php script itself went over the max time. If that was the case, you wouldn't be getting a swiftmailer error, because the script would have simply terminated.

Is your webserver running sendmail? Change the connection host to 'localhost' and see if that helps. If you just want to send an email, then that should work. The only reason you might want to connect to a remote SMTP server is for the From: headers to be correctly set and not be possibly flagged as SPAM on the receving end.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜