php中的邮件和附件

时间:2014-06-12 18:50:15

标签: php file email email-attachments

我试图在php中发送邮件附件。

这是我尝试但不知道这个错误的代码:

请任何人建议对以下代码进行任何修改

<?php
$path = "files/";
$files = "myfile.csv";


$par_mailto = "RECEIVER MAIL ID";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

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

// multipart boundary
$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" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";

// preparing attachments

    $file = fopen($path.$files,"rb");
    $data = fread($file,filesize($path.$files));
    fclose($file);
    $data = chunk_split(base64_encode($data));
    $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files\"\n" .
    "Content-Disposition: attachment;\n" . " filename=\"$files\"\n" .
    "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
    $message .= "--{$mime_boundary}\n";


    //mail attachment ends

    $date = date_default_timezone_set('Asia/Kolkata');
    $today = date("F j, Y, g:i a T");

        $subject = "Test mail on ".$today ;
        $header  .= 'MIME-Version: 1.0' . "\r\n". 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

        $headers = $header."From: info@ziddu.com ". "\r\n"
        . "Cc: $par_mailcc" . "\r\n";
   //!!!All the emails are coming with comma as separator  .... "\r\n\" is important to separate FROM Cc BCc.
       $message .=  "<html><body>";
//                 
       $message .= "<table width='800' cellspacing='5' cellpadding='5' border='0' align='center' style='border:1px solid #e6e6e6'>
  <tbody><tr>
    <td height='80' bgcolor='#F3F3F3' style='padding-left:15px'><table width='100%' cellspacing='0' cellpadding='0' border='0'>
      <tbody><tr>

        <td width='50%' align='center'></td>
      </tr>
    </tbody></table></td>
  </tr>
  <tr>
    <td valign='top' height='150'>
<p style='font:normal 15px Arial,Helvetica,sans-serif;color:#666666;'>Dear Mr. ".$_SESSION['name'].",</p>
<p style='font:normal 15px Arial,Helvetica,sans-serif;color:#666666;'>This is the test mail with an attachment</b></p>
";

$message .= "
<div style='width:584px;background-color:#ffffff;border:#e8e7e7 solid 1px;padding:27px 0;margin:0 auto;border-bottom:0'>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:0px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='400px'> <span style='color:#333333;font-weight:600'>Transaction Details: </span></td>

</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Transfered </td>
<td>USD &nbsp;&nbsp; 10000</td>
</tr>
</tbody>
</table>
</div>
<div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Fee</td>
<td>USD &nbsp;&nbsp; 200</td>
</tr>
</tbody>
</table>
</div>
 <div style='border-bottom:#717171 dotted 1px;font:normal 14px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 10px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>
<tr>
<td width='350px'>Total</td>
<td>USD &nbsp;&nbsp; 4000</td>
</tr>
</tbody>
</table>
</div>
<div style='font:normal 12px Arial,Helvetica,sans-serif;color:#666666;padding:10px 33px 0px'>
<table cellspacing='0' cellpadding='2' border='0' style='width:100%'>
<tbody>

</tbody>
</table>
</div>
</div>
<div style='margin:0 auto;width:594px'><img alt='' src='https://ci4.googleusercontent.com/proxy/Rku_qr-ooNg8yw1tsELcIxO6HBPXzNZtY_bfb9r8yySSxzteTaIxDoJ83pE5XmtwvZO7O5UC4wM31f_rVlP6HyR9VK2OrStgu8llNx45_L81Jv7YD6P1=s0-d-e1-ft#https://dx87hk8eoofvk.cloudfront.net/images/email/receiptedge.png' title=''></div>";

    $message .="<p style='font-family:verdana'><br><b>IMPORTANT:</b>"
               . " Please do not reply to this message or mail address. For any queries,please mail to info@ziddu.com \n\n</p>";
    $message .="<p style='font-family:verdana'><b>DISCLAIMER:</b>"
               . " This communication is confidential and privileged and is directed to and for the use of the addressee only. "
               . "The recipient if not the addressee should not use this message if erroneously received, "
               . "and access and use of this e-mail in any manner by anyone other than the addressee is unauthorized. "
               . "The recipient acknowledges that Ziddu.com may be unable to exercise control or ensure or guarantee the "
               . "integrity of the text of the email message and the text is not warranted as to completeness and accuracy. "
               . "\n\n</p><br>";
    $message .="<p style='font-family:verdana'>Regards,<br>Ziddu Team <br>www.ziddu.com \n\n</p>";
    $message .="</td>
  </tr>
  <tr>
    <td height='30' bgcolor='#E9E9E9' align='center'><strong>Upload.. Share.. Earn!</strong></td>
  </tr>
</tbody></table>";
        @mail($par_mailto, $subject, $message, $headers);


?>

因为我需要在设计中添加更多信息,并且所有信息都需要附加附件。在我出错的地方感到困惑

0 个答案:

没有答案