Solved

PHP sending email BCC and CC

Posted on 2010-09-16
11
444 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
 
LVL 108

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now