Gmail& SwiftMailer致命错误

时间:2014-04-25 01:14:03

标签: php email swiftmailer

我到处寻找,无法找到解决方案。 我刚刚使用GoDaddy托管建立了一个网站。该网站有一个使用Gmail SMTP的表单,当我使用XAMPP运行虚拟主机时,该表单运行正常。然而,在使用GoDaddy托管后,当我尝试提交时出现以下错误:

  

致命错误:未捕获的异常' Swift_TransportException'有消息'无法与主机smtp.gmail.com建立连接[连接拒绝#111]'在/home/modernautoinc/public_html/Swift/lib/classes/Swift/Transport/StreamBuffer.php:259堆栈追踪:#0 /home/modernautoinc/public_html/Swift/lib/classes/Swift/Transport/StreamBuffer.php(64 ):Swift_Transport_StreamBuffer-> _establishSocketConnection()#1 /home/modernautoinc/public_html/Swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(115):Swift_Transport_StreamBuffer-> initialize(Array)#2 / home / modernautoinc / public_html / Swift / lib / classes / Swift / Mailer.php(80):Swift_Transport_AbstractSmtpTransport-> start()#3 /home/modernautoinc/public_html/mech.php(24):Swift_Mailer-> send(Object(Swift_Message) )第259行/home/modernautoinc/public_html/Swift/lib/classes/Swift/Transport/StreamBuffer.php中引发#4 {main}

这是我的php:

<?php

require_once 'Swift/lib/swift_required.php';

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$make = $_REQUEST['make'];
$model = $_REQUEST['model'];
$VIN = $_REQUEST['VIN'];
$problem = $_REQUEST['problem'];

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
    ->setUsername('example@gmail.com')
    ->setPassword('example');

$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Appointment: Mechanical')
    ->setFrom(array($email => $name))
    ->setTo(array('example@gmail.com' => 'MA'))
    ->setBody("From: ".$email."\nName: ".$name."\nPhone Number: ".$phone."\nMake: ".$make."\nModel: ".$model."\nVIN: ".$VIN."\nDescription of Problem: ".$problem);

$mailer->send($message);
header('Location: http://www.google.ca');
?>

非常感谢任何帮助。谢谢你的时间。

1 个答案:

答案 0 :(得分:2)

对于GoDaddy Hosting,我已经配置了我的Silex应用程序:

$app['swiftmailer.options'] = array(
'host'       => 'p3plcpnl0689.prod.phx3.secureserver.net',
'port'       => 465,
'username'   => 'user@host.com',
'password'   => 'your pass',
'encryption' => 'ssl'

);

它就像一个魅力!!