473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

how to add CC & BCC to mailers?

Hi, I'm an html-guy getting his feet wet in PHP.
I DL'd a simple server-side mail script from the 'net and have been trying
to modify it so it includes a CC and BCC function.

the form page contained "to", "name", "from" and "subject" input fields; I
added "CC" and "BCC" inputs, hoping that PHP would say, "ah, yes, indeed..."
But no luck.

I've pasted the main form-page code and the main form-processor code below;
if it's at all possible to include CC and BCC functions in PHP mailers, can
anyone help me with this?

Thanks,
GD
Here's the form page code:
============================

<form name=sds action="mailer.php" METHOD="POST" onsubmit="return check()">

<font color=<? echo($FONTCOLOR); ?>><i>&quot;To&quot; Email:
</font><td><input type="text" name="to" size=27>
<!-- added CC and BCC experiment -->
<font color=<? echo($FONTCOLOR); ?>>&quot;CC&quot; Email??:
</font><td><input type="text" name="cc" size=27>
<font color=<? echo($FONTCOLOR); ?>>&quot;BCC&quot; Email??:
</font><td><input type="text" name="bcc" size=27>
<!-- end addition -->
<font color=<? echo($FONTCOLOR); ?>>&quot;To&quot; Name: * </font><td><input
type="text" name="name" size=27>
<font color=<? echo($FONTCOLOR); ?>>&quot;From&quot; Email:</font><td><input
type="text" name="from" size=27>
<font color=<? echo($FONTCOLOR); ?>>Subject:</font><br><br><td><input
type="text" name="subject" size=29>
<? echo($FONTCOLOR);?<b>Message: * </b></font><br<textarea
name="messagebody" rows=13 cols=55 wrap="physical"></textarea>
<input type="submit" value="Send">

===========================

Here's the main 'guts' of the mail processor:

=============================

<?php

/* recipients */
$to1 = $_POST['to'];

/* message */
$name1 = $_POST['name'];
$from1 = $_POST['from'];
$subject1 = $_POST['subject'];
$messagebody1= $_POST['messagebody'];

/* add cc and bcc var's */

$cc1 = $_POST['cc'];
$bcc1 = $_POST['bcc'];

$messagebody1= str_replace("\\\\","",$messagebody1);
$messagebody1= str_replace("\'","'",$messagebody1);
$messagebody1= str_replace("\\\"","\"",$messagebody1);
$message1 .= $messagebody1."\r\n";
$subject1 = "$subject1";

/* added this: */

$message1 .= "CC :".$cc1."\r\n";
$message1 .= "BCC :".$bcc1."\r\n";

/*end addition */

/* To send HTML mail, you can set the Content-type header. */

$headers1 = "MIME-Version: 1.0\r\n";
$headers1 .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */

$headers1 .= "To: ".$to1."\r\n";
$headers1 .= "From: ".$from1."\r\n";
$headers1 .= "Reply-To: ".$from1."\r\n";
$headers1 .= "Cc: \r\n";

/*echo($to1."<br>");
echo($subject1."<br>");
echo($message1."<br>");
echo($headers1."<br>");

*/

/* and now mail it */

if(@mail($to1, $subject1, $message1, $headers1))

{

echo("<table align=center width=80%><tr><td><font color=$FONTCOLOR>");
echo("Dear $name1,<br>");
echo("<br>");
echo("<b>Here is your Message:</b><br>");
echo("<br>");
echo(" $messagebody1<br><br>");
echo("<h3>Message Sent Successfully</h3>");
echo("<br>");
echo("<br>");
echo("Have a Nice Day!<br>");
echo("SERVER-SIDE MAILER<br>");
echo("<br>");
echo("</font></td></tr></table>");
}

else

{

echo("<br><br><br><br><br>");
echo("Sorry unable to sent the Message.<br>");
echo("<br><br><br><br><br>");

}

?>
Oct 26 '06 #1
3 3855

"George Doka" <se*****@cerius.comwrote in message
news:fj%%g.37052$P7.7590@edtnps89...
Hi, I'm an html-guy getting his feet wet in PHP.
I DL'd a simple server-side mail script from the 'net and have been trying
to modify it so it includes a CC and BCC function.

the form page contained "to", "name", "from" and "subject" input fields; I
added "CC" and "BCC" inputs, hoping that PHP would say, "ah, yes,
indeed..." But no luck.

I've pasted the main form-page code and the main form-processor code
below; if it's at all possible to include CC and BCC functions in PHP
mailers, can anyone help me with this?

Thanks,
GD
Here's the form page code:
============================

<form name=sds action="mailer.php" METHOD="POST" onsubmit="return
check()">

<font color=<? echo($FONTCOLOR); ?>><i>&quot;To&quot; Email:
</font><td><input type="text" name="to" size=27>
<!-- added CC and BCC experiment -->
<font color=<? echo($FONTCOLOR); ?>>&quot;CC&quot; Email??:
</font><td><input type="text" name="cc" size=27>
<font color=<? echo($FONTCOLOR); ?>>&quot;BCC&quot; Email??:
</font><td><input type="text" name="bcc" size=27>
<!-- end addition -->
<font color=<? echo($FONTCOLOR); ?>>&quot;To&quot; Name: *
</font><td><input type="text" name="name" size=27>
<font color=<? echo($FONTCOLOR); ?>>&quot;From&quot;
Email:</font><td><input type="text" name="from" size=27>
<font color=<? echo($FONTCOLOR); ?>>Subject:</font><br><br><td><input
type="text" name="subject" size=29>
<? echo($FONTCOLOR);?<b>Message: * </b></font><br<textarea
name="messagebody" rows=13 cols=55 wrap="physical"></textarea>
<input type="submit" value="Send">

===========================

Here's the main 'guts' of the mail processor:

=============================

<?php

/* recipients */
$to1 = $_POST['to'];

/* message */
$name1 = $_POST['name'];
$from1 = $_POST['from'];
$subject1 = $_POST['subject'];
$messagebody1= $_POST['messagebody'];

/* add cc and bcc var's */

$cc1 = $_POST['cc'];
$bcc1 = $_POST['bcc'];

$messagebody1= str_replace("\\\\","",$messagebody1);
$messagebody1= str_replace("\'","'",$messagebody1);
$messagebody1= str_replace("\\\"","\"",$messagebody1);
$message1 .= $messagebody1."\r\n";
$subject1 = "$subject1";

/* added this: */

$message1 .= "CC :".$cc1."\r\n";
$message1 .= "BCC :".$bcc1."\r\n";

/*end addition */
This is the wrong place to add the $cc1 and $bcc1 information. It should be
added to the headers.

/* To send HTML mail, you can set the Content-type header. */

$headers1 = "MIME-Version: 1.0\r\n";
$headers1 .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */

$headers1 .= "To: ".$to1."\r\n";
$headers1 .= "From: ".$from1."\r\n";
$headers1 .= "Reply-To: ".$from1."\r\n";
$headers1 .= "Cc: \r\n";
This is where you should be adding the $cc1 information.
$headers1 .= "Cc: " . $cc1 . "\r\n";

Shelly
Oct 26 '06 #2
>Hi, I'm an html-guy getting his feet wet in PHP.
>I DL'd a simple server-side mail script from the 'net and have been trying
to modify it so it includes a CC and BCC function.

the form page contained "to", "name", "from" and "subject" input fields; I
added "CC" and "BCC" inputs, hoping that PHP would say, "ah, yes, indeed..."
But no luck.

I've pasted the main form-page code and the main form-processor code below;
if it's at all possible to include CC and BCC functions in PHP mailers, can
anyone help me with this?
Headers go at the beginning of the message, not the end.

Note that it's imperative that you not permit *ANY* user-entered
data to go in any headers (including To:, From:, Subject:, Cc:, and
Bcc:) unless you have checked that this data does not contain
carriage return or line feeds. If you see this in the data, don't
send the mail (and don't fix it, either). Otherwise your form will
be abused by spammers.

Oct 26 '06 #3
Headers go at the beginning of the message, not the end.
>
Note that it's imperative that you not permit *ANY* user-entered
data to go in any headers (including To:, From:, Subject:, Cc:, and
Bcc:) unless you have checked that this data does not contain
carriage return or line feeds. If you see this in the data, don't
send the mail (and don't fix it, either). Otherwise your form will
be abused by spammers.
thanks Shelly & Gordon,

I tried moving the new headers up top of the message code,
but all I get now is 4 identical emails all sent to the primary email;
ie, none to CC or BCC addresses.

here's my code:

================================

/* recipients */
$to1 = $_POST['to'];

/* message */
$name1 = $_POST['name'];
$from1 = $_POST['from'];
$subject1 = $_POST['subject'];
$messagebody1= $_POST['messagebody'];

/* add cc and bcc var's */
$cc1 = $_POST['cc'];
$bcc1 = $_POST['bcc'];
/* To send HTML mail, you can set the Content-type header. */
$headers1 = "MIME-Version: 1.0\r\n";
$headers1 .= "Content-type: text/html; charset=iso-8859-1\r\n";
/* additional headers */
$headers1 .= "To: ".$to1."\r\n";
$headers1 .= "From: ".$from1."\r\n";
$headers1 .= "Reply-To: ".$from1."\r\n";
$headers1 .= "CC: " . $cc1 . "\r\n";
$headers1 .= "BCC: " . $bcc1 . "\r\n";

$messagebody1= str_replace("\\\\","",$messagebody1);
$messagebody1= str_replace("\'","'",$messagebody1);
$messagebody1= str_replace("\\\"","\"",$messagebody1);
$message1 .= $messagebody1."\r\n";

$subject1 = "$subject1";

===============================================
Oct 31 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DrTebi | last post by:
Hello, I have the following problem: I used to "encode" my email address within links, in order to avoid (most) email spiders. So I had a link like this: <a...
0
by: Thomas Scheffler | last post by:
Hi, I runned in trouble using XALAN for XSL-Transformation. The following snipplet show what I mean: <a href="http://blah.com/?test=test&amp;test2=test2">Test1&amp;</a> <a...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
11
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved...
0
by: WB | last post by:
Hi, I'm building a C# Windows application that create marketing mailers for sending to customers. This application needs to create a PDF template, a list of customer names and addresses and...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
12
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
7
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.