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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题