kieron oates kieron oates - 1 year ago 67
HTML Question

How to take javascript from one page and use it in php on another page

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 = ''; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ''; // 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('', '//and their name here'); // Add a recipient
//$mail->addAddress(''); // Name is optional
//$mail->addReplyTo('', '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

Answer Source

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'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download