簡體   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