0

我有一个 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

对于问题 1:

尝试发送带有该类的邮件,而不添加任何变量。因此,只需编写一些程序代码将邮件发送到您自己的地址,看看它是否到达。

对于问题 2:

您正在输入一些文本,$output但您从不输出$output.

于 2013-05-19T12:08:20.777 回答