1

我正在尝试使用 php 发送带有附件的电子邮件。附件已发送,但附件数据在接收方已损坏。接收方适当接收文件大小,然后文件也损坏请帮助我

我的代码

<?php
    ini_set('memory_limit','256M');
    include "phpmailer/class.smtp.php";
    include "phpmailer/class.phpmailer.php";

    $Host = "mail.gmail.com";                       // SMTP servers
    $Username = "*******@gmail.com";    // SMTP password
    $Password = "******";                   // SMTP username

    $From = "*****@gmail.com";
    $FromName = "from";


    $str =$_SESSION['MailAll'];

$arr=explode(",",$str);

print_r ($arr);





    $Tos=$arr;  
//  $Tos=json_encode($Tos);
    $Ccs = array(
        "CC Name 1" => "cc-email-1@yahoo.com",
        "CC Name 2" => "cc-email-2@gmail.com"
    );

    $Subject ="Project Abstract";
    $Body =$_POST['mailcont'] ;;

    $mail = new PHPMailer();

    $mail->IsSMTP();                    // send via SMTP
    $mail->Host     = $Host; 
    $mail->SMTPAuth = true;             // turn on SMTP authentication
    $mail->Username = $Username;  
    $mail->Password = $Password; 

    $mail->From     = $From;
    $mail->FromName = $FromName;
    foreach($Tos as $key => $val){
        $mail->AddAddress($val , $key); 
    }

    //foreach($Ccs as $key => $val){
        //$mail->AddCC($val , $key); 
    //}

    $mail->WordWrap = 50;               // set word wrap
    $mail->Priority = 1; 
    $mail->IsHTML(true); 
/////attachment
    $str=trim($_SESSION['DOCFILE']);//eg-"Time Table Generator.docx","one_size_does_not_fir_all.pdf"

    $arr=explode(",",$str);


  for($i=0;$i<count($arr)-1;$i++){
     $mail->AddAttachment($arr[$i]);
    echo 'array size '.$arr[$i];
}




    $mail->Subject  =  $Subject;
    $mail->Body     =  $Body;




    if(!$mail->Send())
    {
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
    //  header('location:../sendABS.php');
      echo 'Message has been sent.';
    }

?>
4

0 回答 0