Swiftmailer config : E-mail senden mit Google Mail

Kann ich senden E-Mail von meinem pc mit swiftmailer, aber die mail nicht senden in der server.

Ich bin mit swiftmailer 5.0.1. Details zum Projekt sind,

  1. Ein einfaches php-Projekt in netbeans
  2. swiftmailer 5.0.1
  3. Zweig 1.13.1

Mein code ist

public function init() {
        $this->username = '[email protected]'; 
        $this->password = 'password';
        $this->host = 'ssl://smtp.gmail.com';
        $this->port = 465;
        $this->from = '[email protected]';
        $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('[email protected]' => '' . $from_name_add))
                    ->setTo($to_add)
                    ->setContentType($this->body_part_type)
                    ->setBody($this->body);
            $result = $mailer->send($message);
            return $result;
        }

Dieser code funktioniert einwandfrei in meinem pc. Aber nach dem hochladen werden diese code - /Projekt-server, mail-senden nicht. Fehler ist,

    <br />
<b>Fatal error</b>:  Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with 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', '[email protected]', '111111111111', 'Testing mail')
#5 {main}
  thrown in <b>/home/am***/lib/Swift/classes/Swift/Transport/StreamBuffer.php</b> on line <b>259</b><br />

HINWEIS: Es ist bereits ausgeführt, php symfony2 Projekt in diesem server, in diesem Projekt können E-Mails senden erfolgreich.

Hier ist die 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 and other follows. 

Config-details,

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

Ich nur bestanden, diese details, und alle Einstellungen sind Standard. Wenn irgendwelche Infos benötigt werden bitte Fragen, ich ' L post.

Grund, warum ich den Wechsel von symfony2 Projekt zu diesem gewöhnlichen php+swift+twig ist mein hosting ist nur 100 MB und muss ich weitere Bilder hochladen. Aber symfony2 mehr Platz einnehmen.

dies kann nützlich sein : stackoverflow.com/a/46864725/4680523

InformationsquelleAutor Sudhakar Krishnan | 2013-08-08

Schreibe einen Kommentar