View Full Version : Need help adding CC to PHP Contact form

02-05-2010, 06:46 AM
Need help adding CC to email.

I have a very limited knowledge of PHP programing and am attempting yo modify a script for sending an email form from my website. It works fine, but I need it to send a CC or second email to a different address.

Here is the script:

$EmailTo = "myaddress@comcast.net";
$Where = Trim(stripslashes($_POST['where']));
$Subject = "Free Initial Consultation Request Form";
$Tel = Trim(stripslashes($_POST['Tel']));
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$msg = Trim(stripslashes($_POST['Message']));
$human = $_REQUEST['url'];

$headers = "From: <$Email>\r\n";
$headers .= "Reply-To: <$Email>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$Body = '<html><body>';
$Body .= '<h1>Consultation Request Form</h1>';
$Body .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$Body .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>$Name</td></tr>";
$Body .= "<tr><td><strong>Email:</strong> </td><td>$Email</td></tr>";
$Body .= "<tr><td><strong>Telephone:</strong> </td><td>$Tel</td></tr>";
$Body .= "<tr><td><strong>Message:</strong> </td><td>$msg</td></tr>";
$Body .= "</table>";
$Body .= '</body></html>';

if ($human != "") {print "Apparently you are not human";}
else {
if($Name == '') {print "You have not entered a name, please go back and try again";}
else {
if($Email == '') {print "You have not entered an email, please go back and try again";}
else {
if($Tel == '') {print "You have not entered a telephone number, please go back and try again";}
else {
$success = mail($EmailTo, $Subject, $Body, $headers);
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";


I tried adding a cc to the header
with this coding:

$headers .= "Cc: someone@domain.com \r\n";

But it did not work.

Any help you can give will be appreciated.


02-05-2010, 06:57 AM
Based on the examples on PHP's site (http://php.net/manual/en/function.mail.php), your CC header looks correct, although I would remove the space between the email address and the \r\n.

02-06-2010, 02:55 AM
Thanks, I removed the space and the form processes correctly