0

我有一个表格。具有以下内容:

HTML:

<form name="feedback_form" method="post" action="" class="feedback_form">
    <input type="text" name="field-name" value="İsim" title="İsim" class="field-name form_field">
    <input type="text" name="field-email" value="Email" title="Email" class="field-email form_field">
    <input type="text" name="field-subject" value="Başlık" title="Başlık" class="field-subject form_field">
    <textarea name="field-message" cols="45" rows="5" title="Mesajınız..." class="field-message form_field">Mesajınız...</textarea>
    <label for='uploaded_file'>Fotoğrafınızı Yükleyin:</label>
    <input type="file" name="field-file" value="File">
    <br>
    <input type="reset" name="reset" id="reset2" value="Temizle" class="feedback_reset">
    <input type="button" name="submit" class="feedback_go" id="submit2" value="Gönder">                                    
</form>  

PHP:

<?php
header('Content-Type: text/html; charset=utf-8');

function sendFeedback($feedback_email, $feedback_msg, $feedback_name, $feedback_subject, $feedback_file) {


    /* EDIT THIS */
    $admin_email = "mymail@gmail.com";
    if ($feedback_subject == "Subject" || empty($feedback_subject) ) {
        $subj = "Email from your site";
    } else {
        $subj = $feedback_subject;
    }


    /* //EDIT THIS */


    $message = "
    <html>
    <head>
      <title>Websitenizin emaili</title>
    </head>
    <body>
        <p><a href='mailto:".$feedback_email."'>".$feedback_name."</a> send this message:</p>
        <p>".$feedback_msg."</p>
        <p>".$subject."</p>
    </body>
    </html>
    ";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

    if ($feedback_name!=="Name" && $feedback_email!=="Email" && !empty($feedback_email) && !empty($feedback_msg) && !empty($feedback_name) ) {
        if ($feedback_email == "mail_error") {
            echo "<span class='ajaxok'>Geçersiz email adresi.</span>";
        } else {            
            mail($admin_email, $subj, $message, $headers);
            echo "<span class='ajaxok'>Teşekkürler. Mesajınız gönderilmiştir.</span>";  
        }
    } else {
        echo "<span class='ajaxalert'>Lütfen zorunlu alanları doldurunuz.</span>";      
    }


}

sendFeedback($_POST['email'], $_POST['message'], $_POST['name'], $_POST['subject'], $_POST['file']);



?>

在此表单上发送消息时,发送电子邮件,工作。但只有主题、消息、姓名和电子邮件。我想在这个 php 代码中添加图片上传。但我不知道我该怎么做?请帮我。

4

1 回答 1

3

在您必须输入的表格中enctype="multipart/form-data"。在您的 php 文件中,您可以通过$_FILES['file']; 然后查看本教程来访问该文件

于 2012-11-27T22:58:34.107 回答