繁体   English   中英

PHP电子邮件将副本发送给发件人

[英]Php email send copy to sender

我有一个联系表,并且正在使用下面的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');
} 
?>

您可以使用cc n标头

$headers .= 'Cc: somebody@domain.com' . "\r\n";

更多想法

您也可以尝试添加其他这样的邮件功能

mail($email_address,$email_subject,$email_body,$headers);

http://php.net/manual/zh/function.mail.php

使用CC和BCC的示例。

Example#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";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM