swiftmailer mail_send.php error 500-Internal-Server-Error (Log: Timed Out)

1.8k views Asked by At

My System:

  • Operating System: Linux VServer
  • Webserver: apache2 Mailserver (Using IMAP): Dovecot
  • MTA (MailTransportAgent): Postfix + postfix.admin(webapp) to administrate
  • my Domain: acegames.de (137.74.140.78)
  • TLS-Mail-encryption via port 465 is working

What i want to do:

Execute (Button on website->javascript->ajax->php) php script mail_send.php (+ query) to send mail with swiftmail functions. Swiftmail should use my postfix SMTP-Server to send the mail. The swiftmail files are located in /var/www/html/ts/swiftmailer/.

this is http://ts.acegames.de/mail_send.php or /var/www/html/ts/mail_send.php:

<?php 
require_once 'swiftmailer/lib/swift_required.php';

$error = $_GET['err']; $time = $_GET['time']; $user = $_GET['user'];

$transport = Swift_SmtpTransport::newInstance('acegames.de', 465);
$transport->setUsername("[email protected]");
$transport->setPassword("PASS");


$mailer = Swift_Mailer::newInstance($transport);


$message = Swift_Message::newInstance('Teamspeak Error Report');
$message->setFrom(array('[email protected]' => 'USER'));
$message->setTo(array('[email protected]' => 'ts3 report'));
$message->setBody(
'<html>' . 
' <head></head>' . 
' <body>' . 
' <p>Reported Error: ' . $error . '</p>' . 
'  <p>Time: ' . $time . '</p>' . 
'  <p>User: ' . $user . '</p>' . 
' </body>' . 
'</html>', 'text/html' );




// Send the email 
$result = $mailer->send($message); 
?>

But what i get is a 500-INTERNAL_SERVER_ERROR and the following log: /var/log/apache2/error.log:

[:error] [pid 23732] [client 188.174.41.220:49670] PHP Fatal error:   Uncaught exception 'Swift_TransportException' with message 'Connection
to acegames.de:465 Timed Out'  in
/var/www/html/ts/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:404\nStack
trace:\n#0 
/var/www/html/ts/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(289):
Swift_Transport_AbstractSmtpTransport->_getFullResponse(0)\n#1 
/var/www/html/ts/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(117):
Swift_Transport_AbstractSmtpTransport->_readGreeting()\n#2 
/var/www/html/ts/swiftmailer/lib/classes/Swift/Mailer.php(79):
Swift_Transport_AbstractSmtpTransport->start()\n#3 
/var/www/html/ts/mail_send.php(36):
Swift_Mailer->send(Object(Swift_Message))\n#4 {main}\n  thrown in 
/var/www/html/ts/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php
on line 404, referer: https://ts.acegames.de/

I dont know what the issue is. Ive searched through every logfile (mail.log,syslog,apache2 logs,...) but i havent found anything related to this error.

4

There are 4 answers

0
Luke_R On

More Infos requested by @hokusai:

telnet acegames.de 465 Trying 137.74.140.78... Connected to acegames.de. Escape character is '^]'. ... Connection closed by foreign host.

telnet acegames.de 443 Trying 137.74.140.78... Connected to acegames.de. Escape character is '^]'. ... Connection closed by foreign host.

telnet acegames.de 80 Trying 137.74.140.78... Connected to acegames.de. Escape character is '^]'. 301 Moved Permanently

Moved Permanently

The document has moved here.

Apache/2.4.10 (Debian) Server at acegames.de Port 80 ... Connection closed by foreign host.

4
Hokusai On

You have timeout error, I suspect it is a port problem, check if output port is available or blocked.

I mean maybe some port between your client and the server are blocked by a firewall or security policy, spam policy, etc.

1
john On

The error message is saying that it is unable to connect to the mail server you specified. You need to specify TLS like this:

$transport = Swift_SmtpTransport::newInstance('acegames.de', 465, 'tls');

Read more here: Swiftmailer Manual

0
Ralf Hildebrandt On

So, if you control the mailserver on acegames.de, please show the contents of the mail.log (/var/log/mail.log). There's something on Port 465, but the connection is being closed immediately.