如何在swiftmailer中使用bootstrap表单中的数据?

时间:2017-02-02 11:16:16

标签: php forms twitter-bootstrap swiftmailer

嗨,我是php和swift邮件的新手,当我想从bootstrap表单发送数据时,我遇到了这个问题。当我使用引导程序表单时,我收到一封空邮件,但是当我使用一个简单的html表单时,我会收到一个.txt文件,其中包含邮件中表单中的信息。这是我的index.php代码:

<form id="main-contact-form" name="contact-form" method="post" action="contact_email.php" role="form">
            <div class="row  wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
              <div class="col-sm-6">
                <div class="form-group">
                  <input type="text" name="name" class="form-control" placeholder="Name" required="required">
                </div>
              </div>
              <div class="col-sm-6">
                <div class="form-group">
                  <input type="email" name="email" class="form-control" placeholder="Email Address" required="required">
                </div>
              </div>
            </div>
            <div class="form-group">
              <input type="text" name="subject" class="form-control" placeholder="Subject" required="required">
            </div>
            <div class="form-group">
              <textarea name="message" id="message" class="form-control" rows="4" placeholder="Enter your message" required="required"></textarea>
            </div>                        
            <div class="form-group">
              <button type="submit" class="btn-submit">Send</button>
            </div>
          </form>

这是我的contact_email.php代码

<!DOCTYPE html>
<html>
    <head>
    </head>
        <body>

        <?php
        error_reporting(-1);
        ini_set('display_errors', 'On');
        set_error_handler("var_dump");

        $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
        $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
        $subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING);
        $mesage = filter_var($_POST['messsage'], FILTER_SANITIZE_STRING);

        $data = 'Name:  '.$name.'<br />
        Subject:    '.$subject.'<br />
        Email:  '.$email.'<br />
        Message:    '.$mesage;

        require_once 'swift/lib/swift_required.php';

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

        $mailer = Swift_Mailer::newInstance($transport);

        $message = Swift_Message::newInstance('Email From My Website')
          ->setFrom(array('myemail@gmail.com' => 'website'))
          ->setTo(array('myemail@gmail.com'))
          ->setBody($data, text/html);

        if ($mailer->send($message)) {
            echo 'Mail sent successfully.';
        } else {
            echo 'I am sure, your configuration are not correct. :(';
        }
        ?>
    </body>
</html>

请告诉我为什么我收到一封空邮件以及如何修复它以及为什么我在.txt文件中获取信息。提前谢谢你:)

0 个答案:

没有答案