2016-12-01 12:17
浏览 38


So I am making a form which allows the user to input their name, email and comment and i want to take them and put it into a php mail form on another page. i have tested both seperately and both work but i want to have the Name, Email and Comment show up in the php form. can anyone help?

This is the mail system

        require 'PHPMailer/class.phpmailer.php';
        require 'PHPMailer/class.smtp.php';
        require 'PHPMailer/PHPMailerAutoload.php';

        $mail = new PHPMailer;

        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'kieron.testexample1@gmail.com';                 // SMTP username
        $mail->Password = 'testexample';                           // SMTP password
        $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 587;                                    // TCP port to connect to

        $mail->setFrom('//I want their email to go here which is entered on the form', 'Test');
        $mail->addAddress('kieron.textexample@gmail.com', '//and their name here');     // Add a recipient
        //$mail->addAddress('ellen@example.com');               // Name is optional
        //$mail->addReplyTo('info@example.com', 'Information');
        //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
        //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
        $mail->isHTML(true);                                  // Set email format to HTML

        $mail->Subject = 'Here is the subject';
        $mail->Body = '//and i would like the comment to go here';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if (!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';

And this is my input form (uses bootstrap)

<div class="container">
        <div class="row">
            <div class="col-md-6 col-md-offset-3 emailForm">
                <form method="post">
                    <div class="form-group"
                         <label for="name">Your Name:</label>
                        <input type="text" name="userName" class="form-control" placeholder="Your Name"/>
                    <div class="form-group"
                         <label for="email">Your Email:</label>
                        <input type="email" name="userEmail" class="form-control" placeholder="Your Name"/>
                    <div class="form-group"
                         <label for="comment">Your Comment:</label>
                        <textarea class="form-control" name="userComment"></textarea>
                    <input type="submit" class="btn btn-success btn-lg" value="Submit">
    var userName = document.getElementById('userName').value;
    var userEmail = document.getElementById('userEmail').value;
    var userComment = document.getElementById('userComment').value;

(Sorry in advance for any messy code) I just want to take the "var userEmail, userName and userComment" and put them into the php email sender on another page

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzi0602 2016-12-01 12:26

    Change <form method="post"> to <form method="post" action="your_mail_file.php" method="POST"> and then in your mail system file use:

    $userEmail = $_POST['userEmail'];
    $userName = $_POST['userName'];
    $userComment = $_POST['userComment'];
    解决 无用
    打赏 举报

相关推荐 更多相似问题