SwiftMailer一直给出500内部服务器错误

时间:2016-11-21 04:09:04

标签: php email smtp web-hosting

我的网络托管服务器已禁用PHP的邮件功能。我想在我的网站上有一个联系表格,但我过去总是使用PHP的邮件功能。为了绕过禁令,我的主人建议我使用本地SMTP。整天我一直在尝试phpmailer和Swiftmailer,但没有取得多大成功。我知道我正在使用相应的登录信息 - 但每次我尝试发送测试消息时都会收到500错误。我想要的只是一个简单的联系表格!我不得不遗漏一些东西。请帮忙! SwiftMailer测试代码如下:

**Index.Html**
<html>
<head>
    <title>Test form to email</title>
</head>

<body>
<p>
<h1> SwiftMail Test </h1>
<form action="newnew.php" method="post">
<input type="submit" />
</form>
</p>


</body>
</html>

**newnew.php**

include_once "swift_required.php";

$subject = 'Hello!';
$from = array('mywebmail@webmail.com' =>'My Name');
$to = array(
 'myemail@gmail.com'  => 'My Name'
);


$html = "This is a test Email!";
$subject = "Test Subject";

$swift = Swift_Mailer::newInstance($transport);
$transport = Swift_SmtpTransport::newInstance('localhost', 465);
$transport->setUsername('mywebmail@webmail.com');
$transport->setPassword('mypassword');

$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);

if ($recipients = $swift->send($message, $failures))
{
 echo 'Message successfully sent!';
} else {
 echo "There was an error:\n";
 print_r($failures);
}

0 个答案:

没有答案