-1

我有一个 php 表单,我试图从中获取图像作为附件,我对我的代码 1 做了一些修复。我不确定它是否会发送图像(因为我有一些问题)。 . 2. 问题是,当我在服务器中以 index.php 的形式打开它时,页面中甚至显示了注释,甚至没有按钮...

这是代码:

<?php

include_once("functions.php");
// Process
$action = isset($_POST["action"]) ? $_POST["action"] : "";
if (empty($action)) 
{
    // Send back the contact form HTML
    $output = "<form action='#' style='display:none'>
               <input type='file' id='image' name='image' maxlength=50>";
}

require("class.phpmailer.php");
$Email_to = "someone@gmail.com"; // the one that recieves the email
$email_from = "someone@someone.net";
$dir = "uploads/$filename";
chmod("uploads",0777);


function uploadImage($image)
{
    if ((($_FILES["image"]["type"] == "image/gif")
    || ($_FILES["image"]["type"] == "image/jpeg")
    || ($_FILES["image"]["type"] == "image/pjpeg")
    || ($_FILES["image"]["type"] == "image/jpg")
    || ($_FILES["image"]["type"] == "image/png"))
    && ($_FILES["image"]["size"] < 2097152)
    && (strlen($_FILES["image"]["name"]) < 51))
    {
        if ($_FILES["image"]["error"] > 0)
        {
            echo "Return Code: " . $_FILES["image"]["error"];
        }
        else
        {
            echo "Upload: " . $_FILES["image"]["name"] . "<br />";
            echo "Type: " . $_FILES["image"]["type"] . "<br />";
            echo "Size: " . ($_FILES["image"]["size"] / 1024) . " Kb<br />";
            echo "Temp file: " . $_FILES["image"]["tmp_name"] . "<br />";

            if (file_exists("images/" . $_FILES["image"]["name"]))
            {
                echo $_FILES["image"]["name"] . " already exists. ";
            }
            else
            {
                move_uploaded_file($_FILES["image"]["tmp_name"],
                    "images/" . $_FILES["image"]["name"]);
            }
        }
    }
    else
    {
        echo "Invalid file";
    }
$filename = $_FILES["image"]["type"];
$dir = "uploads/$filename";
chmod("uploads",0777);
$success = copy($_FILES[images][tmp_name], $dir);
if ($success) 
    {
    echo " Files Uploaded Successfully<BR>";
    SendIt();
    }
}//end of upload func'


function SendIt() {
//
global $attachments,$Email_to,$Email_msg,$email_subject,$email_from;

$mail = new PHPMailer();
$mail->IsSMTP();// send via SMTP
$mail->Host = "localhost"; // SMTP servers
$mail->SMTPAuth = false; // turn on/off SMTP authentication
$mail->From = $email_from;
$mail->AddAddress($Email_to);
$mail->AddReplyTo($email_from);
$mail->WordWrap = 50;// set word wrap
//now Attach all files submitted
$mail->AddAttachment("uploads"."/".$_FILES["image"]["type"]);

$mail->IsHTML(false);// send as HTML
}


?>

先感谢您!

4

1 回答 1

0

要将图像加入电子邮件,您需要创建一个 MIME 电子邮件,一个简单的 mail() 是不够的。数以万计的模块可以处理这个问题,但 PEAR 的Mail_Mime通常已经在您的环境中可用。

于 2013-05-18T23:28:29.700 回答