Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

php send mail cc field not working

Posted on 2012-09-15
2
Medium Priority
?
653 Views
Last Modified: 2012-09-16
Hi,

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., me@work.com).  The user receives the email, but the CC recipient does not.  I've tried all different variations, but I'm having no luck.  

Thanks.

        // 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));
        fclose($file);

        $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" .
		"--{$mime_boundary}--\n"; 

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

Open in new window

0
Comment
Question by:kimberlys777
2 Comments
 
LVL 8

Accepted Solution

by:
Ahmed Merghani earned 2000 total points
ID: 38402649
Hello,

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

Open in new window

0
 

Author Closing Comment

by:kimberlys777
ID: 38402756
That fixed it -- thanks so much!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

575 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