简体   繁体   English

PHP HTML电子邮件未发送

[英]PHP html email not sending

my php email script doesn't seem to be sending but I can't see why. 我的php电子邮件脚本似乎没有发送,但我不明白为什么。 Also I understand that there are certain security flaws with my script, any advice with that is much appreciated! 我也知道我的脚本存在某些安全缺陷,对此的任何建议都将不胜感激!

thank you 谢谢

  <?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!"; 

 ?>

You are using single quotes around $email1 , these are not necessary. 您在$email1周围使用单引号,但没有必要。 Remove the quotes and it should work just fine. 删除引号,它应该可以正常工作。

Like this 像这样

$to = $email1;

I would advise you to check out the PHPMailer class, this class offers a whole range of features, along with security. 我建议您检查一下PHPMailer类,该类提供了广泛的功能以及安全性。 It is very easy to use, just read through the documentation. 使用非常简单,只需阅读文档即可。

UPDATE 更新

You have not escaped the return and new line special characters at the end of some of the headers. 您还没有在某些标题的末尾转义return和换行符。 Change the end of the lines to look like this: 更改各行的结尾,如下所示:

\r\n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM