现在已经与PHPMailer合作了4个小时,它运行正常并发送邮件。 但是当我附上一个文件时 - 我收到的邮件中没有包含文件。
我只在“File1”中添加了一个文件,当我从脚本中收到邮件时,是否有人看到/说错了什么以及为什么我没有得到附件?
我尝试过:
$mail->AddAttachment($_FILES['file1']['tmp_name'], $_FILES['file1']['name']);
和
$mail->AddAttachment($file1);
没有任何运气附加文件。
我的代码是:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = false;
$mail->Host = 'smtp.curanet.dk';
$mail->Port = 25;
$mail->SetFrom('thomas@test.dk', 'SJ');
$mail->AddAddress('thomas@test.dk', 'SJ');
$mail->Subject = 'Henvendelse fra Hjemmeside';
$besked1 = "Der er flg. henvendelse fra hjemmesiden ang. Tilbud: \n";
$besked1 .= "Navn: " . $_POST['fromname']. "\n";
$besked1 .= "Telefon: " . $_POST['fromtlf']. "\n";
$besked1 .= "E-mail: " . $_POST['fromemail']. "\n";
$besked1 .= "Start dato: " . $_POST['begin_day']. ". " . $_POST['begin_month']. " " . $_POST['begin_year']. "\n";
$besked1 .= "Slut dato: " . $_POST['complete_day']. ". " . $_POST['complete_month']. " " . $_POST['complete_year']. "\n";
$besked1 .= "Budget: " . $_POST['building_budget']. " kr.". "\n";
$besked1 .= "Besked: " . $_POST['frommsg'];
$mail->Body = $besked1;
$mail->IsHTML(false);
$mail->AddAttachment($_FILES['file1']['tmp_name'], $_FILES['file1']['name']);
$mail->AddAttachment($_FILES['file2']['tmp_name'], $_FILES['file2']['name']);
$mail->AddAttachment($_FILES['file3']['tmp_name'], $_FILES['file3']['name']);
/*$mail->AddAttachment($file1);
$mail->AddAttachment($file2);
$mail->AddAttachment($file3);*/
if($mail->send())
{
header('Location: tak.php');
} else {
echo "<script>alert('Mailer Error: " . $mail-> ErrorInfo."')</script>";
}
答案 0 :(得分:2)
问题是你想直接传递文件:
$mail->AddAttachment($_FILES['file1']['tmp_name'], $_FILES['file1']['name']);
但是你必须保存文件然后链接它:
$mail->AddAttachment("path/to/file");
edti:至少这是我之前遇到的问题,临时位置不是一个选项。