PHP邮件程序附件没有上传?

时间:2013-10-01 16:34:14

标签: php html email attachment phpmailer

我正在尝试设置PHP Mailer以允许我从表单发送附件,主要是图像。我有以下代码工作,除了我没有收到附件,他们没有上传。任何人都可以帮助我,或指出我正确的方向,我错过了什么?

PHP

<?php
require 'class.phpmailer.php';

date_default_timezone_set('Europe/London');

$mail = new PHPMailer;

$current=date('l F dS, Y, H:i a');
$mail->From = 'me@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('karina@live.co.uk', 'Karina McG');
$mail->addAddress('me@live.com');
$mail->addReplyTo('noreply@tempur.com');
$mail->addCC('');
$mail->addBCC('');

$mail->addAttachment('/var/tmp/file.tar.gz');
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
$mail->isHTML(true);

$name=$_POST['name'];
$subject=$_POST['subject'];
$system=$_POST['system'];
$country=$_POST['country'];
$description=$_POST['description'];

$mail->Subject = "TEMPUR Web Support Request - $system";
$mail->Body = "Dear $name,<br>
<br>
We have received your TEMPUR request form! - $current<br>
<br>
We will be in contact shortly regarding your issue/s.<br>
<br>
Name : $name <br>
Country : $country <br>
Subject : $subject <br>
System : $system <br>
Description : $description"; 

$mail->AltBody = 'Hehehe';

//$to="$email";//Will change to Digital Users email!

   //Send email
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}

echo 'Message has been sent';

?>

HTML

Upload File:<input type="file" name="upload" id="upload"><br>

1 个答案:

答案 0 :(得分:0)

enctype="multipart/form-data"添加到表单作为属性,如果它不是他们的。

也尝试$mail->addAttachment($_FILES["upload"]["tmp_name"]);

它会起作用。