联系表单被服务器拒绝

时间:2016-02-13 16:35:53

标签: php forms contact

我是新手,所以我在前面道歉。很抱歉第一百万次问这个问题,但我无法收到我的联系表格。我收到服务器错误500.我试图找出这意味着没有成功。我看过所有其他帖子但没有成功。谢谢你的帮助。

这是我的html: 联系表格 - >

<form id="contact-form" action="sendEmail.php" method="post">

<p>
<span>
<input placeholder="Name" type="text" name="name" required>
</span>
</p>

<p>
<span>
<input placeholder="Email" type="email" name="email" required>
</span>
</p>

<p>
<span>
<textarea placeholder="Message" name="message" cols="40" rows="10"></textarea>
</span>
</p>

<p>
<input type="submit" value="Send Message">
</p>

</form>

这是php:

<?php

    // Form Variables
    $sender_name = trim($_POST['name']);
    $sender_email = $_POST['email'];
    $sender_message = $_POST['message'];

    // Configuration Vaiables
    $receiving_email = 'name@email.com'; // Replace this with your own email address
    $receiver_name = 'name'; // replace with your name
    $email_subject = 'Email Sent from Contact Form'; // replace with any default title

    // Require swiftMailer Library
    require_once('lib/classes/swiftMailer/swift_required.php');

    // Create the transport
    $transport = Swift_SmtpTransport::newInstance('smtp.rickstrode.com') // enter SMTP address
      ->setPort(587) // enter SMTP port
      ->setEncryption('ssl') // enter encryption mode
      ->setUsername('name@email.com') // enter SMTP username
      ->setPassword('abcd1234') // enter SMTP password
      ;

    // Create the Mailer using your created Transport
    $mailer = Swift_Mailer::newInstance($transport);

    // Create a Message
    $message = Swift_Message::newInstance($email_subject)
      ->setFrom(array($sender_email => $sender_name))
      ->setTo(array($receiving_email, $receiving_email => $receiver_name))
      ->setBody($sender_message)
      ;

    // Send the Message
    $result = $mailer->send($message);

    // Success and Failure Message
    if ($result) {
        echo "Congratulations, We've received your email. We'll be in touch as soon as we possibly can!";
    } else {
        echo "Unfortunately, Something went wrong while sending the message, Please try again!";
    }

?>

1 个答案:

答案 0 :(得分:0)

您的SMTP服务器名称不正确

$transport = Swift_SmtpTransport::newInstance('smtp.rickstrode.com')

应该是

$transport = Swift_SmtpTransport::newInstance('mail.rickstrode.com')