English 中文(简体)
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.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签