Solved

PHP sending email BCC and CC

Posted on 2010-09-16
11
442 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
Comment Utility
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
Comment Utility
dear Progressed,
it didn't work..
0
 
LVL 3

Expert Comment

by:Progressed
Comment Utility
$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
Comment Utility
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
Comment Utility
my guess my last reply did the work... no more replies from topicstarter...
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:Braveheartli
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thank you,
it wasn't working because of \r\n
0
 
LVL 3

Expert Comment

by:Progressed
Comment Utility
no problem... glad to be of service :)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

743 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

16 Experts available now in Live!

Get 1:1 Help Now