I am getting Gateway timeout error when using swiftmailer on hosted server. But on my PC localhost, its works fine.
When I informed to my hosting, they said they have enabled the outbound connection to port no 465.
Script I have used.
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
require_once 'mailer/lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('myemail@gmail.com')
->setPassword('myapppassword')
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
->setSubject('New Message From ' . $name)
->setFrom(array($email => '$name'))
->setReplyTo($email)
->setTo(array('myemail@gmail.com' => 'My Name'))
->setBody($message)
->addPart('Message: <b>'. $message .'</b>', 'text/html')
;
$result = $mailer->send($message);
if(!$result) {
echo $msg = 'Oops. Something went wrong. Please try again later.';
} else {
echo $msg = 'Thank you. Your query has been submitted. We will contact you back through the provided email address.';
}
Above code used only for hiding headers. But headers are used in order to direct.