i want to use bcc or cc function in this mail function?

不打扰是莪最后的温柔 提交于 2019-11-27 19:35:43

问题


i want to use bcc or cc function in this mail function?

Here My Mail Function

 <?php
//SENDS EMAIL THAT TELLS THE USER TO ACTIVATE THE ACCOUNT
$activation = 'activation.php?key='.$key;
$your_email = 'non-reply@mydomain.pk'; //CHANGE TO YOUR SETTINGS
$domain = $_SERVER["HTTP_HOST"]; //YOUR DOMAIN AND EXTENSION
$to  = $email;
$subject = 'MyDomain Activate Account';
$message .='<img src="http://mydomain.com/images/securedownload.jpg"/>';
$message = 'Welcome,<br/> '.$_POST['username'].'. You must activate your account via   this       message to log in. Click the following link to do so:   http://'.$domain.'/'.$activation;
$headers = 'From: Mydomain<'.$your_email.'@'.$domain.'>\r\n'; //MODIFY TO YOUR SETTINGS
$headers .= 'Content-type: text/html\r\n';
mail($to, $subject, $message,  $headers);
?>

回答1:


You should add to the to and headers part of the mail.

For TO part

$to = "to@to.com, cc@cc.com"

For HEADERS part

$headers .= "To: To Name <to@to.com>\n";
$headers .= "CC: CC Name <cc@cc.com>\n";
$headers .= "BCC: BCC Name <bcc@bcc.com>\n"; 



回答2:


It is very simple, just sharing if anyone gets help from here:

//......
//...Other setting goes here....

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: My Name <myemail@example.com>'. "\r\n";
//Multiple CC can be added, if we need (comma separated);
$headers .= 'Cc: myboss1@example.com, myboss2@example.com' . "\r\n";
//Multiple BCC, same as CC above;
$headers .= 'Bcc: myboss3@example.com, myboss4@example.com' . "\r\n";

mail($to, $subject, $message,  $headers);



回答3:


Just add the Bcc/CC in your Code

<?php
//SENDS EMAIL THAT TELLS THE USER TO ACTIVATE THE ACCOUNT
$activation = 'activation.php?key='.$key;
$your_email = 'non-reply@mydomain.pk'; //CHANGE TO YOUR SETTINGS
$domain = $_SERVER["HTTP_HOST"]; //YOUR DOMAIN AND EXTENSION
$to  = $email;
$subject = 'MyDomain Activate Account';
$message .='<img src="http://mydomain.com/images/securedownload.jpg"/>';
$message = 'Welcome,<br/> '.$_POST['username'].'. You must activate your account via   this       message to log in. Click the following link to do so:   http://'.$domain.'/'.$activation;
$headers = 'From: Mydomain<'.$your_email.'@'.$domain.'>\r\n'; //MODIFY TO YOUR SETTINGS
$headers .=  "BCC: email@domain.com;\r\n"
$headers .= 'Content-type: text/html\r\n';
mail($to, $subject, $message,  $headers);
?>


来源:https://stackoverflow.com/questions/15184267/i-want-to-use-bcc-or-cc-function-in-this-mail-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!