php send mail cc field not working

Posted on 2012-09-15
Last Modified: 2012-09-16

I have a php form that emails the form details to the user, but I also need the email to be cc'd to a particular email address (e.g.,  The user receives the email, but the CC recipient does not.  I've tried all different variations, but I'm having no luck.  


        // to send email
        $to = trim($_POST['email']);
        $subject="Thanks for registration :: ".$site_admin_title;
        // Your message
        $message= "Dear ".$_POST['first_name']." ".$_POST['last_name'].", <br />";
        $message.= "Thank You for registering with Us. <br /><br />";
        $message.="Kindly review the attached document. <br /><br />";
        $message.="<br />Thanks & Regards <br /> Team <br />".$site_admin_title."  <br />";
        $fileatt 			= PDF_PATH.'fifth_annual_SOS_agenda.pdf';
        $fileatt_type 		= "application/pdf"; // File Type
        $fileatt_name 		= 'fifth_annual_SOS_agenda.pdf'; // Filename that will be used for the file as the attachment

        $headers .= 'From: '.$site_admin_title.' <'.EMAIL_FROM.'>';

        $file = fopen($fileatt,'rb');
        $data = fread($file,filesize($fileatt));

        $semi_rand = md5(time());
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

        $headers .= "\nMIME-Version: 1.0\n" .
		"Content-Type: multipart/mixed;\n" . 
		" boundary=\"{$mime_boundary}\""; 

        $message .= "This is a multi-part message in MIME format.\n\n" .
		"--{$mime_boundary}\n" . 
		"Content-Type:text/html; charset=\"UTF-8\"\n" . 
		"Content-Transfer-Encoding: 7bit\n\n" . 
        $message .= "\n\n";

        $data = chunk_split(base64_encode($data));

        $message .= "--{$mime_boundary}\n" .
		"Content-Type: {$fileatt_type};\n" . 
		" name=\"{$fileatt_name}\"\n" . 
        //"Content-Disposition: attachment;\n" .
        //" filename=\"{$fileatt_name}\"\n" .
		"Content-Transfer-Encoding: base64\n\n" . 
        $data .= "\n\n" .

        // Mail it
        $sentmail = @mail($to, $subject, $message, $headers);
        header("Location: thanks.php");

Open in new window

Question by:kimberlys777
    LVL 8

    Accepted Solution


    Add this line before the email function:
    $headers .= 'Cc:' . "\r\n";

    Open in new window


    Author Closing Comment

    That fixed it -- thanks so much!

    Featured Post

    Easy Project Management (No User Manual Required)

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now