Konfiguracja Swiftmailer: wysyłanie poczty przy użyciu gmaila
Mogę wysyłać e-maile z mojego komputera za pomocą swiftmailera, ale nie wysyłam poczty na serwer.
Używam swiftmailera 5.0.1. Szczegóły projektu są,
Prosty projekt php w netbeansswiftmailer 5.0.1gałązka 1.13.1Mój kod to
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;
}
Ten kod działa FINE na moim komputerze. Ale po przesłaniu tego kodu / projektu na serwer, poczta nie jest wysyłana. Błąd jest,
<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->_establishSocketConnection()
#1 /home/am***/lib/Swift/classes/Swift/Transport/AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer->initialize(Array)
#2 /home/am***/lib/Swift/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start()
#3 /home/am***/controller/send_mail.php(54): Swift_Mailer->send(Object(Swift_Message))
#4 /home/am***/public_html/contact.php(43): send_mail->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 />
WSKAZÓWKA: Na tym serwerze istnieje już działający projekt php symfony2, ten projekt może wysyłać pocztę pomyślnie.
Oto kod symfony2,
$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.
Szczegóły konfiguracji to,
mail_contact_from: [email protected]
mail_contact_to: [email protected]
mail_contact_sub: Contact info
Zdałem tylko te szczegóły i wszystkie ustawienia są domyślne. Jeśli potrzebne są jakieś informacje, zapytaj mnie o to.
Powód, dla którego zmieniam projekt symfony2 na zwykły twig php + swift +, to mój hosting ma tylko 100 MB i muszę przesłać więcej zdjęć. Ale symfony2 zajmuje więcej miejsca.