PHPMailer:无法访问网站联系人表单的文件
我发现了类似的主题,但我不擅长PHP,不知道如何处理文件。 我正在为我的网站编写一个联系方式,文本被发送了,但我无法获得附件。我收到错误“无法访问文件”。我可能必须先把附件上传到服务器上,对吗? 这是我的html联系人表单PHPMailer:无法访问网站联系人表单的文件,php,html,Php,Html,我发现了类似的主题,但我不擅长PHP,不知道如何处理文件。 我正在为我的网站编写一个联系方式,文本被发送了,但我无法获得附件。我收到错误“无法访问文件”。我可能必须先把附件上传到服务器上,对吗? 这是我的html联系人表单 <div class="container"> <div class="row"> <div class="col-md-6 " id="form_container">
<div class="container">
<div class="row">
<div class="col-md-6 " id="form_container">
<h2>Contact Us</h2>
<p> Please send your message below. We will get back to you at the earliest! </p>
<form action="mailer.php" role="form" method="post" id="reused_form" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-12 form-group">
<label for="message"> Message:</label>
<textarea class="form-control" type="textarea" id="message" name="message" maxlength="6000" rows="7"></textarea>
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<label for="name"> Your Name:</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="col-sm-6 form-group">
<label for="email"> Email:</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
</div>
<div class="row">
<div class="col-sm-12 form-group">
<label for="name"> Image Upload:</label>
<br/>
<div class="upload-btn-wrapper">
<button type="button" class="btn btn-default" >Browse</button>
<input type="file" name="image" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 form-group">
<button type="submit" class="btn btn-lg btn-default pull-right" >Send</button>
</div>
</div>
</form>
<div id="success_message" style="width:100%; height:100%; display:none; "> <h3>Posted your message successfully!</h3> </div>
<div id="error_message" style="width:100%; height:100%; display:none; "> <h3>Error</h3> Sorry there was an error sending your form. </div>
</div>
</div>
</div>
联系我们
请在下面发送您的消息。我们会尽快给你回复
信息:
你的名字:
电邮:
图像上载:
浏览
发送
成功发布您的消息!
错误抱歉,发送表单时出错。
这是我的PHP代码:
<?php
include "phpmailer.php"; // include the class name
include "smtp.php";
include "exception.php";
$msj= 'Name ' . $_POST["name"] . ' ' .'Nummer ' . $_POST["nummer"] . ' ' . 'Kilometer ' . $_POST["kilometer"];
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
//authentication SMTP enabled
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.switchplus-mail.ch";
//indico el puerto que usa Gmail 465 or 587
$mail->Port = 465;
$mail->Username = "ankauf@7717.ch";
$mail->Password = "xxx";
$mail->SetFrom("ankauf@7717.ch","Ankaufs Formular");
$mail->AddReplyTo("ankauf@7717.ch","ankauf@7717.ch");
$mail->Subject = "Auto Ankaufs Offerte";
$mail->MsgHTML($msj);
$mail->AddAddress("handel@audi-bmw-mercedes.ch");
$mail->AddAttachment($_POST["image"]);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
您需要使用$\u文件
并将enctype=“multipart/form data”
属性添加到表单以访问图像的详细信息这是否回答了您的问题?“我可能必须首先将附件上载到服务器,对吗?”-是的。如果不上传它,PHP就无法以任何方式使用它,因为PHP只在服务器上运行。关于在PHP中处理文件上载