0

可能重复:
如何使用 php 在邮件中附加和显示图像?

我目前在我的网站上设置了一个简单的 php 消息传递系统,供用户向其他用户发送消息。我想知道是否有一种方法可以在消息中包含图像附件,如果可以,我将如何去做。

这是我的代码,它允许用户发送新消息。

<?php 
// CONNECT TO THE DATABASE
    require('includes/_config/connection.php');
// LOAD FUNCTIONS
    require('includes/functions.php');
// GET IP ADDRESS
    $ip_address = $_SERVER['REMOTE_ADDR'];

?>

<?php require_once("includes/sessionframe.php"); ?>


<?php
confirm_logged_in();

    if (isset ($_GET['to'])) {
    $user_to_id = $_GET['to'];

} ?> 

<?php 
//We check if the form has been sent
if(isset($_POST['subject'], $_POST['message_content']))
{
    $subject = $_POST['subject'];
    $content = $_POST['message_content'];
        //We remove slashes depending on the configuration
        if(get_magic_quotes_gpc())
        {
                $subject = stripslashes($subject);
                $content = stripslashes($content);
        }
        //We check if all the fields are filled
        if($_POST['subject']!='' and $_POST['message_content']!='')
        {
            $sql = "INSERT INTO ptb_messages (id, from_user_id, to_user_id, subject, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$user_to_id."', '".$subject."', '".$content."');";
            mysql_query($sql, $connection);

            echo "<div class=\"infobox2\">The message has successfully been sent.</div>";
        }
}


if(!isset($_POST['subject'], $_POST['message_content']))

if (empty($_POST['subject'])){
        $errors[] = 'The subject cannot be empty.';

    if (empty($_POST['body'])){
        $errors[] = 'The body cannot be empty.';

    }
    }

{
?>


<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
  <input name="subject" type="text" id="subject" placeholder="Subject">
    <textarea name="message_content" id="message_content" cols="50" placeholder="Message" rows="8" style="resize:none; height: 100px;"></textarea>
    <input type="image" src="assets/img/icons/loginarrow1.png" name="send_button" id="send_button" value="Send">
</form>
<?php } ?>
4

0 回答 0