问题描述
我正在使用PHPMailer发送PDF文档,它可以正常工作,但是我想在表单中添加一个输入文件,以发送2个附件,即接收PDF和我在输入文件中上传的文件。由于某些原因,我没有输入文件。
当我发送PDF时,它可以工作,但是当我尝试通过表单中的文件输入来发送附件时,则不起作用。
我收到的错误是:
*第150行未定义的索引:foto //有代码$ file = $ _FILES ['foto'] ['tmp_name'];
*第150行试图访问类型为null的值的数组偏移量。
*第187行未定义的变量:file //有代码$ mail-> addAttachment($ file,$ _ FILES ['foto'] ['name']);
*第187行未定义索引:照片
*第187行试图访问类型为null的值的数组偏移量
请有人帮我解决这个问题!
数据>我使用Emailtrap接收电子邮件。 我表单的输入文件的名称为'foto', 我的表单开始如下:
<form class="nobottommargin" method="post" id="bolsa" enctype="multipart/form-data" action="formpdf.PHP" >...
$file= $_FILES['foto']['tmp_name'];
//Corriendo la funcion
sendEmail($pdf,$enquirydata);
//Function to send the @R_735_4045@ion
function sendEmail($pdf,$enquirydata){
$emailbody='';
$emailbody .= '<h1>Email recibido de '. $enquirydata['Fnombre'].'</h1>';
$emailbody .=' <h3>Ver documentos Adjuntos</h3>';
//Para enviar el mensaje en el cuerpo
// foreach ($enquirydata as $title=> $data){
// $emailbody .= '<strong>'. $title . '</strong>: '. $data . '<br />';
// }
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = false; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.mailtrap.io'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'f4f540749a12b0'; // SMTP username
$mail->Password = '20097ae51199a2'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 2525; // TCP port to connect to,use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('[email protected]','PHPMailer');
$mail->AddAddress('[email protected]','Solicitud Empleo');
$mail->addStringAttachment($pdf,'solicitud.pdf');
$mail->addAttachment($file,$_FILES['foto']['name']);
// Content
$mail->isHTML(true);
$mail->Subject = 'Enquiry from' . $enquirydata['Fnombre'];
$mail->Body = $emailbody;
$mail->AltBody = strip_tags($emailbody);
$mail->send();
header('Location:index.PHP');
} catch (Exception $e) {
echo "Message Could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
感谢您的时间。
解决方法
您的表单似乎没有名称,而您正在使用foto
的名称进行访问。将name="foto"
添加到您的html表单中,然后重试。