我想知道如何在这个php脚本中添加一个代码来自动发送一个副本给发件人。我需要这段代码来发送一个准确的副本到发件人的电子邮件。如果有人能帮助我,我会非常appratite。
这是我的联系表格的PHP代码
<?php
define('_EMAIL_TO','[email protected]'); // your email address where reservation details will be received
define('_EMAIL_SUBJECT', 'Booking |Free Consultation'); // email message subject
define('_EMAIL_FROM', $_POST["email"]);
$fields = array(
array('name' => 'name', 'title' => 'Name', 'valid' => array('require')),
array('name' => 'email', 'title' => 'email'),
array('name' => 'number', 'title' => 'Phone Number'),
array('name' => 'required-service', 'title' => 'Required Service'),
array('name' => 'address', 'title' => 'Full Address'),
array('name' => 'consutations-events', 'title' => 'Appointment Date'),
array('name' => 'special-requirements', 'title' => 'Instructions')
);
$error_fields = array();
$email_content = array();
foreach ($fields AS $field){
$value = isset($_POST[$field['name']])?$_POST[$field['name']]:'';
$title = empty($field['title'])?$field['name']:$field['title'];
$email_content[] = $title.': '.nl2br(stripslashes($value));
$is_valid = true;
$err_message = '';
if (!empty($field['valid'])){
foreach ($field['valid'] AS $valid) {
switch ($valid) {
case 'require':
$is_valid = $is_valid && strlen($value) > 0;
$err_message = 'Field required';
break;
case 'email':
$is_valid = $is_valid && preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $value);
$err_message = 'Email required';
break;
default:
break;
}
}
}
if (!$is_valid){
if (!empty($field['err_message'])){
$err_message = $field['err_message'];
}
$error_fields[] = array('name' => $field['name'], 'message' => $err_message);
}
}
if (empty($error_fields)){
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = "From: "._EMAIL_FROM."\r\n";
$headers .= "Reply-To: "._EMAIL_FROM."\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
// Send email
mail (_EMAIL_TO,_EMAIL_SUBJECT, implode('<hr>', $email_content), $headers);
echo ('<header><div><h1>Moorish Gardens</h1></div></header>
<div style="display:block;margin:3%"><br><br><strong style="font-size:24px"><span style="font-size:20px">☺️|</span> Thank You</strong><br><br>Your appointment submitted successfully<br><br>We will be in touch with you as soon as possible.<br>This service will be provided by: <strong>Charaf Ouggag</strong><div class="bttm-tools"><span style="display:inline">Join us @</span> <a id="tw" style="background:#16E1D8" href="https://twitter.com/MoorishGardens" target="_blank">Twitter</a><a id="fb" style="background:#167FE1" href="https://www.facebook.com/Moorishgardens.London" target="_blank">Facebook</a></div></div>');
}else{
echo json_encode(array("code" => 'failed', 'fields' => $error_fields));
}
?>
添加一个额外的头
$headers.="CC:".Additional_email. "rr\n"。