Hello, I'm writing this post as a last resource as I truely cannot figure out my next move.
My goal is to use the PHP swiftmailer class to send email through AWS SES on a single account on my WHM server, it has been working fine before on port 2587 with TLS encryption but a recently cpanel update seems to have blocked this (as it rightly should from a security perspective).
I have tried disabling both options in WHM:
The script works if executed as root, but does not work if executed by the account:
Here is the script:
My goal is to use the PHP swiftmailer class to send email through AWS SES on a single account on my WHM server, it has been working fine before on port 2587 with TLS encryption but a recently cpanel update seems to have blocked this (as it rightly should from a security perspective).
I have tried disabling both options in WHM:
Server Settings -> Tweak Settings ->
Prevent “nobody” from sending mail [?] = off
Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak) [?] = off
Prevent “nobody” from sending mail [?] = off
Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak) [?] = off
The script works if executed as root, but does not work if executed by the account:
Code:
[root:fire] /home/dawn777/public_html/old/automation/include # php -f swtest.php
Message send results: 1
[email protected] [~/public_html/old/automation/include]# php -f swtest.php
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host email-smtp.us-west-2.amazonaws.com [Connection refused #111]' in /home/dawn777/public_html/old/automation/include/swift/lib/classes/Swift/Transport/StreamBuffer.php:266
Stack trace:
#0 /home/dawn777/public_html/old/automation/include/swift/lib/classes/Swift/Transport/StreamBuffer.php(64): Swift_Transport_StreamBuffer->_establishSocketConnection()
#1 /home/dawn777/public_html/old/automation/include/swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer->initialize(Array)
#2 /home/dawn777/public_html/old/automation/include/swift/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start()
#3 /home/dawn777/public_html/old/automation/include/swtest.php(34): Swift_Mailer->send(Object(Swift_Message))
#4 {main}
thrown in /home/dawn777/public_html/old/automation/include/swift/lib/classes/Swift/Transport/StreamBuffer.php on line 266
Here is the script:
Code:
<?
$SMTPhost = "email-smtp.us-west-2.amazonaws.com";
$SMTPuser = "foo";
$SMTPpass = "bar";
$SMTPport = '2587';
$SMTPenc = 'tls';
// echo stream_get_transports();
require_once 'swift/lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance($SMTPhost, $SMTPport, $SMTPenc)
->setUsername($SMTPuser)
->setPassword($SMTPpass)
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom('[email protected]')
->setTo(array('[email protected]'))
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
echo "Message send results: $result";
?>