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

时间:2016-12-01 12:17:23

标签: 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>

(对于任何凌乱的代码提前抱歉) 我只想采取&#34; var userEmail,userName和userComment&#34;并将它们放入另一页的php电子邮件发件人

1 个答案:

答案 0 :(得分:1)

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

$userEmail = $_POST['userEmail'];

$userName = $_POST['userName'];

$userComment = $_POST['userComment'];