我有一个联系表单,我使用下面的PHP脚本从我的联系表单中获取电子邮件。我也想将同一封电子邮件的副本发送给发件人电子邮件。谁能帮我?。谢谢!
<?php
$errors = '';
$myemail = 'chocolatehills_adventurepark@yahoo.com, chocolatehills88@yahoo.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['subject']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Message from: $name";
$email_body = "New message received. ".
" Here are the details:\n \n NAME: $name \n
SUBJECT: $subject \n
EMAIL ADD: $email_address \n
MESSAGE: $message";
$headers = "From: $email_address\n";
//$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-us.php');
}
?>
答案 0 :(得分:2)
答案 1 :(得分:0)
您还可以尝试添加其他邮件功能
mail($email_address,$email_subject,$email_body,$headers);
答案 2 :(得分:0)
http://php.net/manual/en/function.mail.php
使用CC和BCC的例子。
示例#4发送HTML电子邮件
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";