mail.php - add send to cc:

the mail() function

Moderators: egami, macek, gesf

Post Reply
larry29936
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Mar 19, 2020 2:57 pm

Sat Mar 21, 2020 8:12 am

I need to add a cc: $email to the send email and don't know how to accomplish this. My mail.php follows:

Code: Select all

<?php
$subject = $_POST['type'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent=" From: $name  \n Subject: $subject  \n Message: $message";
if ($subject =="Website Problem") {
        $recipient="webmaster@foxclone.com" ;
      }
else{
        $recipient="andyh@foxclone.com";
      }
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='index3.php' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
Thanks in advance,
Larry
If you don't know what you don't know, ask an expert.
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1190
Joined: Mon Feb 22, 2016 5:52 pm

Sat Mar 21, 2020 8:36 am

larry29936
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Mar 19, 2020 2:57 pm

Sun Mar 22, 2020 10:19 am

Got it working doing it this way:

Code: Select all

<?php
$subject = $_POST['type'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name\r\nEmail: $email\r\nMessage: $message";
if ($subject =="Website Problem") {
        $recipient="webmaster@foxclone.com" ;
      }
else{
        $recipient="help@foxclone.com";
      }
$mailheader = "From: $email\r\nBcc: $email\r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank you for contacting us!" . " -" . "<a href='index3.php#contact' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
If you don't know what you don't know, ask an expert.
Post Reply