0

我的 php 电子邮件脚本似乎没有发送,但我不明白为什么。此外,我了解我的脚本存在某些安全漏洞,非常感谢任何建议!

谢谢你

  <?php

include('config.php');

$email1 = $_POST['email1'];

$id = $_POST['id'];
$fname = $_POST['fname'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];


$to = '$email1';
$from = "$email"; 
    $subject = "SC - You Have a Reply"; 

        $body = "<html> 
  <body bgcolor=\"#FFFFFF\"> 
    <center> 
        <b>Dear $firstname</b> <br> 
        <font color=\"red\">You have a response, regarding your Ad on StudentClutter!</font> <br>
         <p> --------------------------------------------------------- </p>
         <b> $fname </b>
         <p> --------------------------------------------------------- </p>
         <p> ".stripslashes($_POST['body'])." </p>
         <br>
         <br>
         <br>
         <p> You can reply to them by email: $emailadd </p>
         <br>
         <br>
         <br>
         <p>Thank you for using studentclutter.com </p>
         <p> -- The Student Clutter Team </p>
    </center> 
  </body> 
</html>";

    // To send the HTML mail we need to set the Content-type header. 
    $headers = "MIME-Version: 1.0rn"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1rn"; 
    $headers  .= "From: $from\r\n"; 

    // now lets send the email. 
    mail($to, $subject, $body, $headers); 

    echo "Message has been sent!"; 

 ?>
4

1 回答 1

1

您在 周围使用单引号$email1,这些不是必需的。删除引号,它应该可以正常工作。

像这样

$to = $email1;

我建议您查看PHPMailer类,该类提供了一系列功能以及安全性。它非常易于使用,只需阅读文档即可。

更新

您没有在某些标题的末尾转义回车和换行特殊字符。将行尾更改为如下所示:

\r\n";
于 2012-12-17T22:19:19.170 回答