繁体   English   中英

电子邮件phpmailer中的附件

[英]attached file in email phpmailer

我想在线申请职位功能。 我已经编写了以下代码来上传简历,但是如果用户单击“应用”,他将要发送上载的简历作为电子邮件附件。 我正在使用phpmailer并成功发送电子邮件,但没有附加文件。

这是我上传文件的代码:

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{

    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];

    $fp      = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    fclose($fp);

    if(!get_magic_quotes_gpc())
    {
        $fileName = addslashes($fileName);
    }
    $connect=mysql_connect("localhost","root","") or die("Couldnt connect");
    mysql_select_db("dbname") or die("Couldnt DB");

    $query = "INSERT INTO upload (name, size, type, content ) ".
        "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
        mysql_query($query) or die('Error, query failed');

    echo "<br>File $fileName uploaded<br>";

    $uploads_dir = 'uploads/';
    move_uploaded_file($tmpName, "$uploads_dir/$fileName");

}

这是PHPmailer代码:

$mail->AddAttachment("uploads"."/".$fileName);  

我已经创建了“上载”文件夹,并且正在其中获取所有上载的文件。 但是我没有将文件作为电子邮件附件上传。

您的PHP版本是什么? 我在class.phpmailer.php类中找到了一些东西。 搜索此函数: 私有函数EncodeFile($ path,$ encoding ='base64')

这里是:

  private function EncodeFile($path, $encoding = 'base64') {
try {
  if (!is_readable($path)) {
    throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
  }
  if (function_exists('get_magic_quotes')) {
    function get_magic_quotes() {
      return false;
    }
  }
   if (PHP_VERSION < 6) {
     $magic_quotes = get_magic_quotes_runtime();
     set_magic_quotes_runtime(0);
   }
  $file_buffer  = file_get_contents($path);
  $file_buffer  = $this->EncodeString($file_buffer, $encoding);
   if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }

  return $file_buffer;
} catch (Exception $e) {
  $this->SetError($e->getMessage());
  return '';
}

}

如您所见,此函数正在检查您的PHP_VERSION。 如果低于6(PhpVersion 6将被删除,请使用magic_codes函数!!!),并尝试使用某些magic_quotes函数,但在Php5或更高版本中已弃用

因此...您可以通过检查* magic_quotes *函数是否可用或使用简单的代码注释来解决此问题,从而通过* function_exists *完成PhpMailer源代码。

尝试此答案,似乎在附加正文时出现问题,以某种方式破坏了附件,我想通过PHPMailer添加附件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM