php - Swiftmailer config : send mail using gmail -


i can send email pc using swiftmailer, mail not sending in server.

i'm using swiftmailer 5.0.1. project details are,

  1. a simple php project in netbeans
  2. swiftmailer 5.0.1
  3. twig 1.13.1

my code is

public function init() {         $this->username = 'username@gmail.com';          $this->password = 'password';         $this->host = 'ssl://smtp.gmail.com';         $this->port = 465;         $this->from = 'username@gmail.com';         $this->subject = 'company - contact';         $this->body_part_type = 'text/html';     }  public function send_email($from_name_add, $to_add, $fullname, $email, $mobile, $content) {             $this->init();             $transport = swift_smtptransport::newinstance($this->host, $this->port)                     ->setusername($this->username)                     ->setpassword($this->password);              $mailer = swift_mailer::newinstance($transport);              $message = swift_message::newinstance();             $cid = $message->embed(swift_image::frompath('../public_html/pic/logo.png'));             $this->body = $this->renderemailtemplate('email', $fullname, $email, $mobile, $content, $cid);             $message->setsubject($this->subject)                     ->setfrom(array('username@gmail.com' => '' . $from_name_add))                     ->setto($to_add)                     ->setcontenttype($this->body_part_type)                     ->setbody($this->body);             $result = $mailer->send($message);             return $result;         } 

this code works fine in pc. after upload code/project server, mail not sending. error is,

    <br /> <b>fatal error</b>:  uncaught exception 'swift_transportexception' message 'connection not established host ssl://smtp.gmail.com [connection timed out #110]' in /home/am***/lib/swift/classes/swift/transport/streambuffer.php:259 stack trace: #0 /home/am***/lib/swift/classes/swift/transport/streambuffer.php(64): swift_transport_streambuffer-&gt;_establishsocketconnection() #1 /home/am***/lib/swift/classes/swift/transport/abstractsmtptransport.php(115): swift_transport_streambuffer-&gt;initialize(array) #2 /home/am***/lib/swift/classes/swift/mailer.php(80): swift_transport_abstractsmtptransport-&gt;start() #3 /home/am***/controller/send_mail.php(54): swift_mailer-&gt;send(object(swift_message)) #4 /home/am***/public_html/contact.php(43): send_mail-&gt;send_email('am*** inc', 'fe****@gma...', 'asdf', 'asdf@in.com', '111111111111', 'testing mail') #5 {main}   thrown in <b>/home/am***/lib/swift/classes/swift/transport/streambuffer.php</b> on line <b>259</b><br /> 

hint: there allready running php symfony2 project in server, project can send mail successfully.

here symfony2 code,

$message = \swift_message::newinstance()                 ->setsubject($sub)->setfrom($from)->setto($to)->setcontenttype("text/html")                 ->setbody($this->renderview('fzam***bundle:layout:mail.html.twig', array                     ('name' => $this->fullname, 'mobile' => $this->mobile, 'email' => $this->email,                     'content' => $this->content, 'time' => $this->sys_time, 'ip' => $userip,                     'server_time' => date('y-m-d h:i:s'))         )); try {             $this->get('mailer')->send($message); // catch , other follows.  

config details are,

mail_contact_from: username@gmail.com   mail_contact_to:   username@gmail.com   mail_contact_sub:   contact info 

i passed details , settings default. if info needed please ask i'l post.

reason i'm changing symfony2 project ordinary php+swift+twig hosting 100mb , need upload more images. symfony2 occupy more space.

looks live server missing openssl, need enable in order secure connections working (i.e. enable php_openssl module). check this question.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -