duanfangbunao36970 2016-12-01 12:17
浏览 38
已采纳

如何从一个页面获取javascript并在另一个页面上的php中使用它

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->addCC('cc@example.com');
        //$mail->addBCC('bcc@example.com');
        //$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>
                    <div class="form-group"
                         <label for="email">Your Email:</label>
                        <input type="email" name="userEmail" class="form-control" placeholder="Your Name"/>
                    </div>
                    <div class="form-group"
                         <label for="comment">Your Comment:</label>
                        <textarea class="form-control" name="userComment"></textarea>
                    </div>
                    <input type="submit" class="btn btn-success btn-lg" value="Submit">
                </form>
            </div>
        </div>
    </div>
    <script>
    var userName = document.getElementById('userName').value;
    var userEmail = document.getElementById('userEmail').value;
    var userComment = document.getElementById('userComment').value;
    </script>

(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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘