我试图让我的表单附加文件但是无法正常工作。
现在500内部服务器错误:
我的代码是:
HTML
<form action="email2.php" method="post" class="form" id="form1" name="contact-form" enctype="multipart/form-data">
<input type="file" name="userfile" id="file-1" class="inputfile inputfile-1" data-multiple-caption="{count} files selected" multiple />
</form>
PHP email2.php
<?php
/**
* PHPMailer simple file upload and send example
*/
$msg = '';
if (array_key_exists('userfile', $_FILES)) {
// First handle the upload
// Don't trust provided filename - same goes for MIME types
// See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
// Upload handled successfully
// Now create a message
// This should be somewhere in your include_path
require 'PhpMailerAutoload.php';
$mail->setFrom('CV');
$mail->addAddress('kubographics@gmail.com', 'Eugenio Keller');
$mail->Subject = 'PHPMailer file sender';
$mail->msgHTML("My message body");
// Attach the uploaded file
$mail->addAttachment($uploadfile, 'My uploaded file');
if (!$mail->send()) {
$msg = "Mailer Error: " . $mail->ErrorInfo;
} else {
$msg = "Message sent!";
}
} else {
$msg = 'Failed to move file to ' . $uploadfile;
}
}
?>
PhpMailerAutoload.php
你可以在github中获得的常规文件。所以我不明白这个问题,有什么帮助吗?