gpt4 book ai didi

PHPMailer - AddAttachment 不工作

转载 作者:行者123 更新时间:2023-11-28 00:01:22 26 4
gpt4 key购买 nike

我有一个 Web 表单,它使用 phpmailer 函数将表单内容通过电子邮件发回给我。我正在尝试添加一个 AddAttachment 功能,但我似乎在 php.ini 文件中遇到了问题。

这是我的 html 片段:

<td>
<div align="right">Add attachment :</div>
</td>
<td colspan="2">
<input type="file" name="uploaded_file" id="uploaded_file" />
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
</td>

这是我的 php;

<?php

require 'PHPMailerAutoload.php';

$mail = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mailer.********.local"; // SMTP server

$mail->From = $_POST['email'];
$mail->AddAddress("frank********@gmail.com");

$mail->Subject = "Request for Contract Registration for " . $_POST['name'];
$mail->Body = "Supplier number : " . $_POST['suppno'] . "\r\n";
$mail->Body .= "Payee name : " . $_POST['name'] . "\r\n";
$mail->Body .= "Address : " . $_POST['add'] . "\r\n";
$mail->Body .= " : " . $_POST['add2'] . "\r\n";
$mail->Body .= " : " . $_POST['add3'] . "\r\n";
$mail->Body .= "Nature of business : " . $_POST['nob'] . "\r\n";
$mail->Body .= "Tax Ref : " . $_POST['rctref'] . "\r\n";
$mail->Body .= "Description of works : " . $_POST['descofwks'] . "\r\n";
$mail->Body .= "Start date of contract : " . $_POST['stdte'] . "\r\n";
$mail->Body .= "End date of contract : " . $_POST['enddte'] . "\r\n";
$mail->Body .= "Location of contract : " . $_POST['location'] . "\r\n";
$mail->Body .= "Estimated value of contract : " . $_POST['contractval'] . "\r\n";
$mail->Body .= "Confirm contract : " . $_POST['confirm'] . "\r\n";
$mail->Body .= "Declaration : " . $_POST['declaration'] . "\r\n";
$mail->Body .= "Department : " . $_POST['dept'] . "\r\n";

$mail->AddAttachment($_POST['uploaded_file']);

$mail->WordWrap = 50;

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';

header('Location: confirm.htm');
}
?>

我的路径有问题吗???这可能是我想念的简单事情,但如果有人能帮助我,我将不胜感激!提前谢谢你,弗兰克。

最佳答案

而不是使用

 $mail->AddAttachment($_POST['uploaded_file']); // WRONG

试试这个

if (isset($_FILES['uploaded_file']) &&
$_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
$_FILES['uploaded_file']['name']);
}

上传的文件存储在临时文件夹中。您应该从文件系统添加附件,为此使用 $_POST 是错误的。

关于PHPMailer - AddAttachment 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21183147/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com