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

标签 javascript php html

所以我正在制作一个表单,允许用户输入他们的姓名、电子邮件和评论,我想将它们放入另一个页面上的 php 邮件表单中。我已经分别测试了两者,并且都有效,但我希望姓名、电子邮件和评论显示在 php 表单中。有人可以帮忙吗?

这是邮件系统

        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';
    }

这是我的输入表单(使用 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>

(对于任何困惑的代码提前表示歉意) 我只想将“var userEmail、userName 和 userComment”放入另一个页面上的 php 电子邮件发送器中

最佳答案

更改<form method="post"><form method="post" action="your_mail_file.php" method="POST">然后在您的邮件系统文件中使用:

$userEmail = $_POST['userEmail'];

$userName = $_POST['userName'];

$userComment = $_POST['userComment'];

关于javascript - 如何从一个页面获取 javascript 并在另一页面上的 php 中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40910467/

相关文章:

html - CSS 定位和列表项的问题

javascript - 无法使用 angular-summernote summarnote 函数未定义

php - 获取数据并检查一次查询中是否有 "Next Page"?

php - 自定义 PayPal 按钮的自动 OpenSSL 加密? PHP

html - 在 HTML 5 中单击图像时添加声音

javascript - 在每张打印纸中重复内容

javascript - javascript 中是否有用于日期/时间的自然语言解析器?

javascript - 如何使用 Javascript 数据表

javascript - NodeJS 中的访问计数器

php - 拉拉维尔 5 : Extend a Facade