当用户输入电子邮件包含在其他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.

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.

Several reasons why mailing to different user-defined addresses may not work:

1.) Check the result from the mail() call is TRUE, just to make sure the underlying sendmail (if you are on Linux) did not return an error.

2.) Add additional headers to prevent problems when delivering mails to foreign SMTP hosts, an example may be found on PHP doc for mail()

3.) In some cases (i.e. when using SMTP on Windows) using the PEAR Mail package may solve your problem. It also supports ASMTP and error trapping is much easier compared to the mail() function.