可能重复:
PHP 邮件、抄送字段
我的任务是在客户网站上的表单中添加抄送。我真正需要的只是将表格提交给指定为 theemail@address.com 的收件人,然后抄送(抄送)到另一个电子邮件地址。
这是我在 doctype (HTML 5) 上方文档顶部的 PHP 方面的内容
<?php
if(isset($_POST['submit'])) {
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
if(!isset($hasError)) {
$emailTo = 'theemail@address.com';
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: Sigma Web Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>