dtkago3208 2014-03-10 17:40
浏览 141

当用户输入电子邮件包含在其他PHP文件中时,PHP mail()将不会发送

I am generating a page of information from a database. I need to send an email with the page content as a reminder. (example here takes input as message) It takes in an email address and is supposed to send the details to that address.

<div class="container">
        <?php
            $name = $_GET['info'];

            if(isset($name)){

                $info = explode('|', $name);

                /*****************************************************
                        open conection to the mySQL database
                ******************************************************/
                                         ....
                /*****************************************************
                        Populate the page 
                ******************************************************/
                $sql="Select information from table";

                $result = mysqli_query($con,$sql);


                while($row = mysqli_fetch_array($result))
                {
                    /*Title*/
                    echo '<h1>'.$row['post_title'].'</h1><hr>';

                    /*content*/
                    echo '<h2>Details: </h2><br>'.$row['post_content'].'<br>';

                    $content = $row['post_title'];

                    /*Reminder*/
                    echo '<div data-role="collapsible">
                        <h1>Send a reminder</h1>';
                        include("includes/email_reminder.php");             
                    echo'</div>';
                }


                /*****************************************************
                        Close connection
                ******************************************************/
                mysqli_close($con);

            } else {

                echo'Nothing selected. Go back <br> 
                <a href="#" data-rel="back"> <img src="img/icon/Back.png" style="height: 3em" > </a>';

            }
        ?>

    </div>

That creates a form at the bottom of the page to take in the email that needs that needs a reminder. This is email_reminder.php:

<?php
function spamcheck($field)
{
    // Sanitize e-mail address
    $field=filter_var($field, FILTER_SANITIZE_EMAIL);
    // Validate e-mail address
    if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}
?>

<?php
    // display form if user has not clicked submit
    if (!isset($_POST["submit"]))
    {
?>    

<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">

Your Email: <input type="text" name="to"><br>

Subject: <input type="text" name="subject"><br>

Message: <textarea rows="10" cols="40" name="message"></textarea><br>

<input type="submit" name="submit" value="Submit Feedback">

</form>

<?php 
    }
    else    // the user has submitted the form

    {
        // Check if the "from" input field is filled out
        if (isset($_POST["to"]))
        {
            // Check if "from" email address is valid
            $receivecheck = spamcheck($_POST["to"]);

            if ($receivecheck==FALSE)
            {
                echo "Invalid input";
            }

            else
            {
                $to = $_POST["to"]; //receiver

                $subject = $_POST["subject"];

                $message = $_POST["message"];

                // message lines should not exceed 70 characters (PHP rule), so wrap it
                $message = wordwrap($message, 70);

                // send mail
                mail("$to",$subject,$message,"From: myaddress@mail.com
");

                echo "reminder has been sent";
            }
        }
    }
?>    

I have used that form in isolation (just opened email_reminder.php on its own) and it sent emails correctly from whichever email address I used. It just doesn't send when included in the other script.

  • 写回答

2条回答 默认 最新

  • dopt85756 2014-03-11 20:20
    关注

    include(emai_reminder.php); needs single quotes surrounding the file name (and email correctly spelled: include('email_reminder.php');

    But, it looks like you need more help than just this. For example, there is no field FROM in your form, although you reference $_POST["from"]. You're running validation against that variable, which doesn't exist, which fails validation, which prevents the else if block from running, which prevents mail() from ever being called.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分