如何从一个页面获取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

dtrnish3637
dtrnish3637 我想避免使用ajax,我对表单的工作方式有了大致的了解
接近 4 年之前 回复
douxiuar885064
douxiuar885064 你知道表格是如何运作的吗?你知道如何捕获PHP中表单发送的输入吗?你知道$_POST是什么吗?
接近 4 年之前 回复

1个回答



&lt; form method =“post”&gt; </ code>更改为&lt; form method =“ 发布“action =”your_mail_file.php“method =”POST“&gt; </ code>然后在您的邮件系统文件中使用:</ p>

  $ userEmail = $ _POST ['  userEmail']; 

$ userName = $ _POST ['userName'];

$ userComment = $ _POST ['userComment'];
</ code> </ pre>
</ div>

展开原文

原文

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

dongzhong2018
dongzhong2018 是的,有效,谢谢
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐