You are here: how to add CC & BCC to mailers? « PHP Programming Language « IT news, forums, messages
how to add CC & BCC to mailers?

Posted by George Doka on 10/26/06 09:35

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>");

}

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация