【问题标题】:PHP Mail, CC FieldPHP 邮件,抄送字段
【发布时间】:2019-04-10 22:31:55
【问题描述】:

如何在此函数中包含 CC 字段?

function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
    $file = $path.$filename;
    $file_size = filesize($file);
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = chunk_split(base64_encode($content));
    $uid = md5(uniqid(time()));
    $name = basename($file);
    $header = "From: ".$from_name." <".$from_mail.">\r\n";
    $header .= "Reply-To: ".$replyto."\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: text/html; charset=iso-8859-1\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $message."\r\n\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
    $header .= $content."\r\n\r\n";
    $header .= "--".$uid."--";
    if (mail($mailto, $subject, "", $header)) {
        echo  "OK"; // or use booleans here
    } else {
        echo  "ERROR!";
    }
}

【问题讨论】:

  • 任何一个答案都可以...您是否考虑过使用库(phpmailer、swiftmailer、pear::mail 等...)让您的生活更轻松?

标签: php email


【解决方案1】:

在声明标题时添加:

$headers .= 'Cc: somebody@domain.com' . "\r\n";

【讨论】:

    【解决方案2】:

    Reply-To-line 之后添加$header .= "CC: ".$cc."\r\n";

    http://www.w3schools.com/PHP/func_mail_mail.asp

    【讨论】:

      【解决方案3】:

      请不要建立自己的 MIME 电子邮件。请改用PHPMailer 之类的东西。更容易使用且不易碎。添加 CC 就像这样简单:

      $mail = new PHPMailer();
      $mail->AddCC('somebody@example.com');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-28
        • 1970-01-01
        • 2012-03-20
        • 2011-07-24
        • 2015-12-19
        • 2015-01-01
        • 2016-02-08
        相关资源
        最近更新 更多