PHP mail and bcc

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
badlt
Forum Newbie
Posts: 3
Joined: Mon Aug 31, 2009 1:53 pm

PHP mail and bcc

Post by badlt »

Hello, I am trying to figure out how to add a "BCC' field to the following script:

Code: Select all

<?php 
$to = $_REQUEST['sendto'] ; 
$from = $_REQUEST['Email'] ; 
$name = $_REQUEST['Name'] ; 
$headers = "From: $from";
$subject = "Subject goes ehre
 
$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Email"} = "Email"; 
$fields{"Message"} = "Message"; 
 
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 
 
$headers2 = "From: email@email.com"; 
$subject2 = "Thank you for contacting Company."; 
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours. If you have any more questions, please consult our website at http://www.oursite.com";
 
if($from == '') {print "You have not entered an email, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a name, please go back and try again";} 
else { 
$send = mail($to, $subject, $body, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
if($send) 
{header( "Location: http://www.oursite.com/thankyou.htm" );} 
else 
{print "We encountered an error sending your mail, please notify webmaster@oursite.com"; } 
}
}
?>
Any ideas???
Last edited by Benjamin on Mon Aug 31, 2009 2:10 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: PHP mail and bcc

Post by Darhazer »

Code: Select all

$headersArray = array();
$headersArray['From'] = $from;
$headersArray['Bcc'] = $bcc;
$headers = implode(PHP_EOL, $headersArray);
I believe you'll find where you should put this :)
And sanitize your input! If you use this on a live site, it can be exploited to send spam
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP mail and bcc

Post by Benjamin »

:arrow: Moved to PHP - Code
badlt
Forum Newbie
Posts: 3
Joined: Mon Aug 31, 2009 1:53 pm

Re: PHP mail and bcc

Post by badlt »

Darhazer wrote:

Code: Select all

$headersArray = array();
$headersArray['From'] = $from;
$headersArray['Bcc'] = $bcc;
$headers = implode(PHP_EOL, $headersArray);
I believe you'll find where you should put this :)
And sanitize your input! If you use this on a live site, it can be exploited to send spam
Sorry, I am new to this. I grabbed the code from someone else. I have no idea how to 'sanitize' the code or where to insert what you sent me. I wanted to insert a fixed email address for the BCC. Is that possible?
badlt
Forum Newbie
Posts: 3
Joined: Mon Aug 31, 2009 1:53 pm

Re: PHP mail and bcc

Post by badlt »

badlt wrote:
Darhazer wrote:

Code: Select all

$headersArray = array();
$headersArray['From'] = $from;
$headersArray['Bcc'] = $bcc;
$headers = implode(PHP_EOL, $headersArray);
I believe you'll find where you should put this :)
And sanitize your input! If you use this on a live site, it can be exploited to send spam
Sorry, I am new to this. I grabbed the code from someone else. I have no idea how to 'sanitize' the code or where to insert what you sent me. I wanted to insert a fixed email address for the BCC. Is that possible?
Nevermind... I figured it out myself :)
Post Reply