【问题标题】:Emailing Form Data with PHP使用 PHP 通过电子邮件发送表单数据
【发布时间】:2016-12-22 19:31:20
【问题描述】:

我得到了要发送到正确电子邮件的电子邮件,但是他们正在发送这个。

电子邮件:$email
用户名:$username
密码:$password
确认密码:$cpassword
主题标签:$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>

PHP 代码在这里:

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

我只是想把从表单中收集的数据输入到 php 中,这样它就可以通过电子邮件将表单信息发送给我。谢谢

【问题讨论】:

  • 当你想在字符串中使用变量时,使用双引号:“$variable bla bla”。否则字符串中的 '$email' 不会被实际值替换。

标签: javascript php html forms email


【解决方案1】:

您使用了单引号。不解析单引号内的变量。

这将起作用:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 2012-01-19
    相关资源
    最近更新 更多