Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法访问phpmailer函数中的文件错误_Php_Email - Fatal编程技术网

无法访问phpmailer函数中的文件错误

无法访问phpmailer函数中的文件错误,php,email,Php,Email,我编写了这段代码,使用php mailer通过HTML表单发送邮件,但是在单击submit按钮后,它向我显示了这个错误“无法访问文件”。我几乎什么都试过了,但似乎不起作用。 如果有人能帮我,那就太好了 表格编号: <form name="contactform" role="form" name="contactForm" action="send_form_careers.php" method="post" novalidate enctype="multipart/form-dat

我编写了这段代码,使用php mailer通过HTML表单发送邮件,但是在单击submit按钮后,它向我显示了这个错误“无法访问文件”。我几乎什么都试过了,但似乎不起作用。 如果有人能帮我,那就太好了

表格编号:

 <form name="contactform" role="form" name="contactForm" action="send_form_careers.php" method="post" novalidate enctype="multipart/form-data">
                    <div class="col-xs-12">
                        <label for="name">Full Name</label><br>
                        <input type="text" id="name" name="name" class="text" required><br><br>
                        <label for="phone">Phone</label><br>
                        <input type="tel" id="phone" name="phone" class="text" required><br><br>
                        <label for="email">Email</label><br>
                        <input type="email" id="email" name="email" class="text" required><br><br>          
                        <input type="file" name="my_file" id="my_file" class="inputfile" required />
                        <label for="file">Upload Your Resume</label>
                        <div class="button" style="text-align:center">
                            <input type="submit" class="btn btn-read" value="Submit" name="submit">
                        </div>
                   </div>
                   </form>

全名


电话


电子邮件


上传你的简历
php文件

<?php 
include('phpmailer/class.phpmailer.php');

try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled

$to = "giteshnnd@gmail.com";
$mail->AddAddress($to);
$mail->From       = $_POST['email'];
$mail->FromName   = $_POST['name'];
$mail->Subject  = "Test Email using PHP";

$body             = "<table>
                         <tr>
                            <th colspan='2'>This Sample Mail</th>
                         </tr>

                         <tr>
                            <td style='font-weight:bold'>Name :</td>
                            <td>".$_POST['name']."</td>
                         </tr>

                         <tr>
                          <td style='font-weight:bold'>E-mail : </td>
                          <td>".$_POST['email']."</td>
                        </tr>

                        <tr>
                          <td style='font-weight:bold'>Phone : </td>
                          <td>".$_POST['phone']."</td>
                        </tr>

                        <tr>
                          <td style='font-weight:bold'>Message : </td>
                          <td>".$_POST['message']."</td>
                        </tr>
                     <table>";
$body             = preg_replace('/\\\\/','', $body); //Strip backslashes
$mail->MsgHTML($body);

$mail->IsSMTP();                           // tell the class to use SMTP
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = 25;                    // set the SMTP server port
//$mail->Host       = "mail.yourdomain.com"; // SMTP server
//$mail->Username   = "name@domain.com";     // SMTP server username
//$mail->Password   = "password";            // SMTP server password

$mail->IsSendmail();  // tell the class to use Sendmail
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap   = 80; // set word wrap

$mail->AddAttachment($_FILES['file']['tmp_name'],
                     $_FILES['file']['name']);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e->errorMessage();

}

?>

名为“我的文件”的输入文件。看:

但您从命名索引“文件”中寻址了
$\u文件

正确代码:

$mail->AddAttachment($_FILES['my_file']['tmp_name'],
                     $_FILES['my_file']['name']);

可能的重复我不明白,如何修复?请检查您的文件路径文件路径是否正确。请先检查您的文件路径。1.您的表单操作是
action=“send\u form\u careers.php”
2。因此,您的
send\u form\u careers.php将与表单文件3位于同一文件夹中。发送
include的_form_careers.php文件('phpmailer/class.phpmailer.php')
因此,您的send_form_careers.php和此文件结构将为phpmailer/4。请检查您的文件权限,该权限为644
$mail->AddAttachment($_FILES['my_file']['tmp_name'],
                     $_FILES['my_file']['name']);