Reputation: 5297
I want to send mails using php script in localhost. Via google I found switchmailer. I tried the following code using swiftmailer.
<?php
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587)
->setUsername('[email protected]')
->setPassword('gmailpassword')
;
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('[email protected]' => 'John Doe'))
->setTo(array('[email protected]', '[email protected]' => 'A name'))
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
?>
The code was giving error in lase line $result = $mailer->send($message);
The php error log file contains following info
[error] [client 127.0.0.1] PHP Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Network is unreachable #101]' in /home/shashwat001/public_html/swift/lib/classes/Swift/Transport/StreamBuffer.php:259\nStack trace:\n#0 /home/shashwat001/public_html/swift/lib/classes/Swift/Transport/StreamBuffer.php(64): Swift_Transport_StreamBuffer->_establishSocketConnection()\n#1 /home/shashwat001/public_html/swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer->initialize(Array)\n#2 /home/shashwat001/public_html/swift/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start()\n#3 /home/shashwat001/public_html/swift/index.php(31): Swift_Mailer->send(Object(Swift_Message))\n#4 {main}\n thrown in /home/shashwat001/public_html/swift/lib/classes/Swift/Transport/StreamBuffer.php on line 259
The reason seems to be that I am connected to a LAN network so behind a proxy server. Nothing is there much on net regarding proxy settings in switchmailer.
Is there any way to send mails anywhere outside LAN using localhost behind proxy server?
Upvotes: 2
Views: 3055
Reputation: 3026
The correct port for Google Mail is 465, Google also uses SSL for connections to Gmail.
Upvotes: 1