Jump to content

Trying to add CC and BCC to script


MissShona

Recommended Posts

Hello,

 

I need help with the following script (generated at http://www.thesitewizard.com)  I customized it just a tad (adding a few fields).  My issue is that I would like to CC: the person who fills out the form (so they get a copy in their own e-mail....so I want to use the $email variable) and also a BCC: to an internal member of another affiliate.  Here's the script:

 

$mailto = '[email protected]' ;

 

 

// $subject - set to the Subject line of the email, eg

//$subject = "Feedback Form" ;

 

$subject = "Referred by CLE" ;

 

// the pages to be displayed, eg

//$formurl = "http://www.example.com/feedback.html" ;

//$errorurl = "http://www.example.com/error.html" ;

//$thankyouurl = "http://www.example.com/thankyou.html" ;

 

$formurl = "http://www.shonasporch.com/CLE/Riemerpopup.html" ;

$errorurl = "http://www.shonasporch.com/CLE/no.html" ;

$thankyouurl = "http://www.shonasporch.com/CLE/thankyou.html" ;

 

$uself = 0;

 

// -------------------- END OF CONFIGURABLE SECTION ---------------

 

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;

$name = $_POST['name'] ;

$email = $_POST['email'] ;

$comments = $_POST['comments'] ;

$phone = $_POST['phone'];

$contact = $_POST['contact'];

$http_referrer = getenv( "HTTP_REFERER" );

 

 

 

if (!isset($_POST['email'])) {

header( "Location: $formurl" );

exit ;

}

if (empty($name) || empty($email) || empty($comments)) {

  header( "Location: $errorurl" );

  exit ;

}

if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {

header( "Location: $errorurl" );

exit ;

}

 

if (get_magic_quotes_gpc()) {

$comments = stripslashes( $comments );

}

 

$messageproper =

 

"This message was sent from:\n" .

"The Collegiate Learning Exchange Newsletter\n" .

"------------------------------------------------------------\n" .

"Name of sender: $name\n" .

"Email of sender: $email\n" .

"Phone: $phone\n".

"Preferred: $contact\n".

"------------------------- MESSAGE -------------------------\n\n" .

$comments .

"\n\n------------------------------------------------------------\n" ;

 

mail($mailto, $subject, $messageproper,

"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "CC: [email protected]" . $headersep . "BCC: <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );

header( "Location: $thankyouurl" );

exit ;

 

?>

 

The message prints the CC:, but it does not actually come through.  I tried to define the e-mails with the $headersep variable, but kept getting parsing errors;  even after defining $headersep after $email.  I have an old book on PHP which does not address CC and BCC at all.  Online, I can't find any example where a variable is used for the e-mail recipient.  Any ideas?

 

Oh, and if you want to see the form, it is: http://www.shonasporch.com/CLE/Riemerpopup.html

Link to comment
https://forums.phpfreaks.com/topic/37549-trying-to-add-cc-and-bcc-to-script/
Share on other sites

Try this:

<?php
$mailto = '[email protected]' ;
$yourheaders = 'Reply-To: \"$name\" <$email>' . "\r\n";
$yourheaders .= 'To: Bill <[email protected]>, Kelly <[email protected]>' . "\r\n";
$yourheaders .= 'Cc: [email protected]' . "\r\n";
$yourheaders .= 'Bcc: [email protected]' . "\r\n";


// $subject - set to the Subject line of the email, eg
//$subject   = "Feedback Form" ;

$subject = "Referred by CLE" ;

// the pages to be displayed, eg
//$formurl      = "http://www.example.com/feedback.html" ;
//$errorurl      = "http://www.example.com/error.html" ;
//$thankyouurl   = "http://www.example.com/thankyou.html" ;

$formurl = "http://www.shonasporch.com/CLE/Riemerpopup.html" ;
$errorurl = "http://www.shonasporch.com/CLE/no.html" ;
$thankyouurl = "http://www.shonasporch.com/CLE/thankyou.html" ;

$uself = 0;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$phone = $_POST['phone'];
$contact = $_POST['contact'];
$http_referrer = getenv( "HTTP_REFERER" );



if (!isset($_POST['email'])) {
   header( "Location: $formurl" );
   exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
   header( "Location: $errorurl" );
   exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
   header( "Location: $errorurl" );
   exit ;
}

if (get_magic_quotes_gpc()) {
   $comments = stripslashes( $comments );
}

$messageproper =

   "This message was sent from:\n" .
   "The Collegiate Learning Exchange Newsletter\n" .
   "------------------------------------------------------------\n" .
   "Name of sender: $name\n" .
   "Email of sender: $email\n" .
   "Phone: $phone\n".
   "Preferred: $contact\n".
   "------------------------- MESSAGE -------------------------\n\n" .
   $comments .
   "\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
   "From: \"$name\" <$email>" . $headersep . $yourheaders . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.