douqiao8370 2017-02-14 09:13
浏览 23
已采纳

表单中的内容未发送到webmail

I'm creating a form using Swiftmailer. The problem is, nothing from inside the form, but the PHP body appear in the email. I've also watch some tutorial from Youtube and Google, tried them but failed, nothing working yet.

HTML

<form id="contactForm" method="POST" action="form-process.php">
            <div class="row">
                <div class="form-group col-md-6">
                    <label class="h4">Your Name</label>
                    <input type="text" class="form-control" id="name" placeholder="Enter name" required data-error="NEW ERROR MESSAGE">
                    <div class="help-block"></div>
                </div>
                <div class="form-group col-md-6">
                    <label class="h4">Your Email</label>
                    <input type="text" class="form-control" id="email" placeholder="Enter name" required>
                    <div class="help-block"></div>
                </div>
            </div>
            <div class="form-group">
                    <label class="h4">Your Message</label>
                    <textarea id="message" class="form-control" rows="5" placeholder="Enter your message" required></textarea>
                    <div class="help-block"></div>
                </div>
                <button type="submit" id="form-submit" class="btn btn-success btn-lg pull-right ">Submit</button>
        <div id="msgSubmit" class="h3 text-center hidden"></div>
        <div class="clearfix"></div>
        </form>

PHP

<?php

require_once 'swiftmailer-5.x/lib/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('mail.mysite.com', 465, 'ssl')
  ->setUsername('mysite@domain.com')
  ->setPassword('password')
  ;

// Get data 

$name=filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$message=filter_var($_POST['message'], FILTER_SANITIZE_STRING);

$data = "Name: " . $name . "<br />" .
        "Email: " . $email . "<br />" .
        "Message: " . $message . "<br />";

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

// Create a message
$message = Swift_Message::newInstance('Feedback Form')
  ->setFrom(array('mysite2@domain.com' => 'Feedback Form'))
  ->setTo(array('mysite@domain.com' => 'Feedback Form'))
  ->setBody($data, 'text/html')
  ;

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

?>
<p>Thank you for give us your feedback. We will respond to your feedback as soon as possible.</p>
<p>Please click <button type="btn btn-success"><a href="contact.html">Here</a></button> to return to the site.</p>

Here's the screen capture

enter image description here

What i've done wrong? Help me. (Using Bootstrap as the form)

  • 写回答

2条回答 默认 最新

  • douxiong3234 2017-02-14 09:20
    关注

    OK, it looks like you are missing the name attribute to your form inputs.

    Add the attributes, and then your form should work, e.g.:

    <input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required data-error="NEW ERROR MESSAGE">
    <input type="text" class="form-control" id="email" name="email" placeholder="Enter name" required>
    <textarea id="message" class="form-control" name="message" rows="5" placeholder="Enter your message" required></textarea>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来