0

我正在使用一个 PHP 脚本来发送带有 php 变量的电子邮件(通过使用 POST 方法的表单获得)。这是我的代码:

<?php
/* These will gather what the user has typed into the fieled. */

$nameField = $_POST['name'];
$emailField = $_POST['email'];
$questionField = $_POST['question'];

/* These are the variable that tell the subject of the email and where the email will be sent.*/

$emailSubject = 'Recupero password LightSchool';
$mailto = $_POST['email'];
$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';

/* This takes the information and lines it up the way you want it to be sent in the email. */

$body = '<br><hr><br> Name: '.$name.' <br> Email: '.$email.' <br> Question: '.$question.' <br>';

$headers = "From: $email\r\n"; // This takes the email and displays it as who this email is from.
$headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text.
$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.

?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title>MY Studenti</title>
    <link rel="stylesheet" href="style.css" type="text/css" />
    </head>  
    <body style="background-image:url(http://studenti.lightschool.it/new/bkg.png)">  
    <div id="main">
    <h1>
    <img src="http://images.lightschool.it/logo/medium250x250.png" alt="" height="66" style="float: left; margin-right: 20px" width="62" />MY Studenti</h1>
    <p>Recupera password ti permette di recuperare la tua password, tramite 
    l'inserimento del tuo nome utente.</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <form id="form1" name="form1" method="post" action="reset-pwd.php">
<table width="455" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="175" height="44" align="center"><label for"name">name</label></td>
    <td width="280"><input name="name" type="text" id="name" size="30" />
      </td>
  </tr>
  <tr>
    <td height="45" align="center"><label for="email">email</label></td>
    <td><input name="email" type="text" id="email" size="30" /></td>
  </tr>
  <tr>
    <td height="41" align="center"><label for="question">question</label></td>
    <td><textarea name="question" cols="30" rows="5" id="question"></textarea></td>
  </tr>
  <tr>
    <td height="38">&nbsp;</td>
    <td><label>
      <input type="submit" name="Submit" id="Submit" value="Submit" />
    </label></td>
  </tr>
</table>

</form>
    </div>
    </body>
    </html>

此 PHP 脚本成功运行,但有三个变量(姓名、电子邮件和问题)不会显示在发送的电子邮件中。我也试过这个var_dump($_POST['email']);没有解决。我怎么解决这个问题?

谢谢。

PS:我知道这个网站和其他网站上发布了很多这样的问题,但这些发布的解决方案都没有帮助我。

4

2 回答 2

4

改变

$nameField = $_POST['name'];
$emailField = $_POST['email'];
$questionField = $_POST['question'];

$name = $_POST['name'];
$email = $_POST['email'];
$question = $_POST['question'];
于 2013-03-28T14:37:06.847 回答
1

您将 Vars 称为两个不同的东西。你要小心这个。如果您没有过滤掉任何人的电子邮件,那么有人可以向它提供地址列表并开始从您的邮箱发送垃圾邮件。

于 2013-03-28T14:39:51.343 回答