发送副本电子邮件到发件人在PHP?

时间:2020-05-06 19:05:54

标签: php email post methods

我想知道如何在此php脚本中添加代码,以自动将副本发送给发件人。我需要此代码才能将确切的副本发送到发件人的电子邮件。 如果有人可以帮我,我会非常感激。

这是我联系表格的php代码

<?php
define('_EMAIL_TO','appointments@moorish-gardens.com'); // 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>&nbsp;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:&nbsp;<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));
}
?>

1 个答案:

答案 0 :(得分:0)

添加额外的标题

$ headers。 =“ CC:”。Additional_email。 “ \ r \ n”;