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 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧