MissShona Posted February 7, 2007 Share Posted February 7, 2007 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 = 'Rishona@gmail.com' ; // $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: missniceness79@yahoo.com" . $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 Quote Link to comment https://forums.phpfreaks.com/topic/37549-trying-to-add-cc-and-bcc-to-script/ Share on other sites More sharing options...
quasiman Posted February 12, 2007 Share Posted February 12, 2007 Try this: <?php $mailto = 'Rishona@gmail.com' ; $yourheaders = 'Reply-To: \"$name\" <$email>' . "\r\n"; $yourheaders .= 'To: Bill <bill@example.com>, Kelly <kelly@example.com>' . "\r\n"; $yourheaders .= 'Cc: john@example.com' . "\r\n"; $yourheaders .= 'Bcc: mike@example.com' . "\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 ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/37549-trying-to-add-cc-and-bcc-to-script/#findComment-182795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.