如何解决未定义的变量:mime_boundary

时间:2016-01-15 08:03:15

标签: php

我的代码plz为我提供了解决方案

<?php
    class email
    {
      function emailWithAttach($fromaddress,$toAddress,$mailSubject,$mailMessageHead,$mailMessageMain,$mailMessageSign,$filePath,$fileName)
     {
     $fileatt_name = $fileName;
     $fileatt = $filePath.$fileName;
     $fileatt_type = "application/octet-stream";
     $email_from = $fromaddress;
     $email_subject = $mailSubject;
     $email_message = $mailMessageHead."<br>";
     $email_message .= $mailMessageMain."<br>";
     $email_message .= $mailMessageSign;
     $headers = '';
     $email_to = $toAddress;
     $headers = "From: ".$email_from;
     $file = fopen($fileatt, 'rb');
     $data = fread($file,filesize($fileatt));
     fclose($file);
     empty($mime_boundary); /*i also tried empty function still getting notice.*/
     $semi_rand = md5(time());
     $mime_boundary = "==Multipart_Boundary_X{$semi_rand}X";

     $headers .= "\nMIME-Version: 1.0\n" .
      "Content-Type: multipart/mixed;\n" .
      " boundary=\"{$mime_boundary}\"";

      $email_message .= "This is a multi-part message in MIME format.\n\n" .
      "--{$mime_boundary}\n" .
      "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
      "Content-Transfer-Encoding: 7bit\n\n" .
      $email_message .= "\n\n";

      $data = chunk_split(base64_encode($data));

      $email_message .= "--{$mime_boundary}\n" .
      "Content-Type: {$fileatt_type};\n" .
      " name=\" {$fileatt_name}\"\n" .
      "Content-Transfer-Encoding: base64\n\n" .
      $data .= "\n\n". /*i m getting error on this line */
      "--{$mime_boundary}--\n";


      if(@mail($email_to, $email_subject, $email_message, $headers))
      {
          return true;
      }
      }
    } 
    ?>

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

$mime_boundary = isset($mime_boundary) ? $mime_boundary : '';

取代:

empty($mime_boundary);

但我觉得这没有意义......你的函数中不存在这个变量($ mime_boundary),所以这是空的。您可以跳过此检查并删除此行。