Reputation: 115
i am using the below PHP Script to get emails to my from my contact form. i want to send a copy of the same email to the sender email also. how can i do that... can some one add some lines to my script to do that..
can i separate multiple emails in $emailTo like $emailTo = '[email protected], $email';
if(!isset($hasError)) {
$emailFrom = '[email protected]';
$emailTo = '[email protected]';
$subject = 'Submitted message from '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: ' .' <'.$emailFrom.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
// set our boolean completion value to TRUE
$emailSent = true;
}
Adding another FUNCTION might work. but i am searching for some other easy way to do that in same function :)
PS: i want to add a aditional line to sender like "your email copy of message that you sent to xxx owner"
Upvotes: 4
Views: 19151
Reputation: 329
Hope this helps
<?php
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$course = $_POST['course'];
// Create the email and send the message
$to = $email_address; //This is the email address of the person who filled the form, this email will be supplied by the sender.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your Website contact form.\n\n"."Here are the details:\n\n
Name: $name\n\n
Email: $email_address\n\n
Phone: $phone\n\n
Course:\n$course";
$headers = "From: noreply@yourdomain\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= 'Cc: [email protected]' . "\r\n"; // Add your email address replacing [email protected] - This is where the form will send the message to.
$headers .= "Reply-To: $email_address";
mail($to, $email_subject,$email_body,$headers);
return true;
?>
Upvotes: 2
Reputation: 45
You can try like this to send a cc copy to sender email
$headers["From"] = "$from";
$headers["To"] = "$email";
$headers["Subject"] = $subject;
$headers['Cc'] = '$from';
Upvotes: -2
Reputation: 669
You can do it by writing
$emailTo = '[email protected], [email protected]';
Upvotes: 0
Reputation: 5705
See php.net/mail example #4 on how to extend the $additional_headers
parameter to add a CC recipient:
$headers = 'From: ' .' <'.$emailFrom.'>' . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'Cc: ' .' <[email protected]>';
Upvotes: 1