将cc,bcc和附件添加到电子邮件中

时间:2017-04-04 11:40:33

标签: php email

我想在PHP的邮件功能中使用CC和BCC某些地址,但CC / BCC电子邮件无法成功发送。

<?php

$emailto = "umair.khan2313@yahoo.com,umair.khan666666@gmail.com";
$contacts = explode(",", $emailto);
array_walk($contacts, 'trim');

foreach($contacts as $contact) {
    $cc = "umair.khan1366@yahoo.com";
    $bcc = "amaan.khan13@yahoo.com";
    $tto = $contact;

    $tto. ="CC: $cc\r\n";
    $tto .= "BCC: $bcc\r\n";
    $subject = "hey";
    $body = "Test";

    $header = 'From: My Name <umair.khan666@gmail.com>'
        . "\r\n";
    $header = "CC: CC Name <$cc>\n";
    $header = "BCC: BCC Name <$bcc>\n";
    if(mail($tto, $subject, $body, $header)) {
        echo "SEND";
    }
}

如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

您需要连接$ header值。所以只需使用“$ header。=”而不是“$ header =”

答案 1 :(得分:0)

以下是您的脚本的简单修复 -

在第一个附加行的前面添加换行符:

$tto .= "\r\nCC: $cc\r\n";  # here is the change
$tto .= "BCC: $bcc\r\n";