我加入了CC,以在客戶網站上填寫表單的任務。我真正需要的是將表單提交給指定爲[email protected]的收件人,並將其抄送(碳複製)到另一個電子郵件地址。
這裏就是我有PHP明智的,在DOCTYPE上述文件的頂部(HTML 5)
<?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._%-][email protected][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 = '[email protected]';
$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;
}
}
?>
CC是一個頭。只需將它添加到你的'$ headers'字符串中即可。 –
誰讓你使用'if(function_exists('stripslashes'))'?您是否錯誤地修改了不專業的magic_quotes解決方法? – mario
還應該指出這是令人討厭的代碼。看看SwiftMailer等。人。如果你想這樣做的話。 – Treffynnon