dongwu9063 2016-11-21 04:09
浏览 69

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

My web host has PHP's mail function disabled. I'd like to have a contact form on my site, but I've always used PHP's mail function in the past. To get around the ban my host suggested I use local SMTP instead. All day I've been trying phpmailer and Swiftmailer without much success. I know I'm using the appropriate log in information - but each time I try to send a test message I receive a 500 error. All I want is a simple contact form! I have to be missing something. Please help! SwiftMailer test code is written below:

**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:
";
 print_r($failures);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 关于无人驾驶的航向角
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了