Solved

PHP sending email BCC and CC

Posted on 2010-09-16
11
445 Views
Last Modified: 2013-12-12
I have a web form to send email
I use PHP
I send it like this

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: www.mypage.com\r\nReply-To: webmaster@mypage.com";
mail($mymail, $subject, $message, $headers, $address);

I like to add CC and BCC,
how can I add it?
0
Comment
Question by:Braveheartli
  • 5
  • 5
11 Comments
 
LVL 3

Expert Comment

by:Progressed
ID: 33689610
add some rows to your headers!


$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: www.mypage.com\r\nReply-To: webmaster@mypage.com";
$headers .= 'Cc: yourCC@adress.com' "\n";
$headers .= 'Bcc: yourBCC@adres.com' "\n";

mail($mymail, $subject, $message, $headers, $address);

this should do the trick
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 33689644
dear Progressed,
it didn't work..
0
 
LVL 3

Expert Comment

by:Progressed
ID: 33689694
$to .= 'recieveremail@domain.com';
$subject .= "whats the subject";

//  send HTML mail
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

// Additional headers
$headers .= 'To: RECIEVERNAME <reciever@domain.com>' . "\r\n";
$headers .= 'From: www.mypage.com <youremail@domain.com>' . "\r\n";
$headers .= 'Cc: CCemail@domain.com' . "\r\n";
$headers .= 'Bcc: BCCemail@domain' . "\r\n";

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


this is what I got and it works perfect!
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 33689762
I'm pretty sure the \r\n line terminators are necessary.  Also, "it didn't work.." is not an error message.  It's helpful if you can tell us what the symptoms are.
0
 
LVL 3

Expert Comment

by:Progressed
ID: 33689974
my guess my last reply did the work... no more replies from topicstarter...
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 33690161
Dear Ray_Paseur, and Progressed;

When I write it like this,

$mymail="my1email@mymail.com";

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'To: my1email@mymail.com' . "\r\n";
$headers .= "From: mydomain.com\r\nReply-To: webmaster@mydomain.com";
$headers .= 'Cc: my2emai@mymail.com' . "\r\n";
$headers .= 'Bcc: my3emai@mymail.com' . "\r\n";
mail($mymail, $subject, $message, $headers);

I recieve this email my1email@mymail.com on the To section.
but I can not recieve email2 or email3
thank you
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 33690172
on the To section of thecoming email I see this email twice "my1email@mymail.com" but CC and BCC parts are empty..
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 33690199
if I delete
$headers .= 'To: my1email@mymail.com' . "\r\n";
it still sends the email to :

$mymail="my1email@mymail.com";
mail($mymail, $subject, $message, $headers, $address);
0
 
LVL 3

Assisted Solution

by:Progressed
Progressed earned 250 total points
ID: 33690329
Why are you setting mymail as to in the mail() function?

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

in the headers you give YOUR emailadresses in from/cc/bcc in the $header section
0
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 33690446
thank you,
it wasn't working because of \r\n
0
 
LVL 3

Expert Comment

by:Progressed
ID: 33690473
no problem... glad to be of service :)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question