0

我正在使用此代码发送电子邮件:

$email="abc@gmail.com";
$to = $email;
$subject = "Test mail";
$message1 = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head></head>
  <body>
    <div  style="width:80%;">
      <table style="margin: 10px 20px 10px 20px;">
        <tr><td>Hello!'."  ".'</td></tr>';
        $message1.=$mailmessage;
        $message1.=
          '<tr><td>Please find attachments for dailyreport.</td></tr>
<tr><td><br>' . "Thanks and Regards with ". '</td></tr>
    </table></div>
  </body>
</html>';
$from = "admin@feed.com";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";  
if(mail($to,$subject,$message1,$headers)) {
  "mail sent";
} else {
  "email does not exist";
}

要发送附件,我需要将内容类型更改为Content-Type: multipart/mixed;\n. 但是 HTML 上下文会改变。如何将文件附加到此 html?

4

3 回答 3

1

如果您想编写自己的脚本,请查看此链接

但我强烈建议您使用自定义库,例如 PHPMailer http://code.google.com/a/apache-extras.org/p/phpmailer/

PHPMailer 是一个 PHP 电子邮件传输类,具有文件附件、SMTP 服务器、抄送、密件抄送、HTML 消息、自动换行等。通过 sendmail、PHP mail()、QMail 或直接使用 SMTP 发送电子邮件。即将支持其他传输,例如 SMS、MMS

于 2012-11-17T08:48:35.393 回答
0

You have some special headers for email attachment, Don't worry we have a php class called sendMail, download and learn @ PHP sendMail class

于 2012-11-17T08:59:06.253 回答
0

您应该尝试使用此代码获取标头信息

$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}\""; 
于 2012-11-17T08:49:43.377 回答