向发件人 PHP 联系脚本发送电子邮件副本


Send a Copy of email to Sender PHP contact script

我正在使用下面的PHP脚本从我的联系表格中获取电子邮件。 我还想将同一电子邮件的副本发送给发件人电子邮件。 我该怎么做...有人可以在我的脚本中添加一些行来做到这一点..

我可以像$emailTo = 'owner@website.com, $email';这样的$emailTo中分隔多封电子邮件吗

if(!isset($hasError)) {
    $emailFrom = 'smptcontactemail@website.com';
    $emailTo = 'owner@website.com';
    $subject = 'Submitted message from '.$name;
    $sendCopy = trim($_POST['sendCopy']);
    $body = "Name: $name 'n'nEmail: $email 'n'nComments: $comments";
    $headers = 'From: ' .' <'.$emailFrom.'>' . "'r'n" . 'Reply-To: ' . $email;
    mail($emailTo, $subject, $body, $headers);
    // set our boolean completion value to TRUE
    $emailSent = true;
}

添加另一个函数可能会起作用。 但我正在寻找其他一些简单的方法来在同一函数中做到这一点:)

PS:我想为发件人添加一个附加行,例如"您发送给xxx所有者的邮件的电子邮件副本"

那将是

$headers .= 'Cc: anotheremail@domain.net' . "'r'n";

希望这有帮助

<?php
            $name = $_POST['name'];
            $email_address = $_POST['email'];
            $phone = $_POST['phone'];
            $course = $_POST['course'];
// Create the email and send the message
            $to = $email_address; //This is the email address of the person who filled the form, this email will be supplied by the sender.
            $email_subject = "Website Contact Form:  $name";
            $email_body = "You have received a new message from your Website contact form.'n'n"."Here are the details:'n'n
            Name: $name'n'n
            Email: $email_address'n'n
            Phone: $phone'n'n
            Course:'n$course";
            $headers = "From: noreply@yourdomain'n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
            $headers .= 'Cc: youremail@yourdomain.com' . "'r'n"; // Add your email address  replacing yourname@yourdomain.com - This is where the form will send the message to.
            $headers .= "Reply-To: $email_address"; 
            mail($to, $email_subject,$email_body,$headers);
            return true;            
?>

请参阅示例 #4 php.net/mail 了解如何扩展 $additional_headers 参数以添加抄送收件人:

$headers = 'From: ' .' <'.$emailFrom.'>' . "'r'n" . 'Reply-To: ' . $email . "'r'n" . 'Cc: ' .' <some@mail.com>';

你可以

通过编写来做到这一点

$emailTo = 'owner@website.com, customer@website.com';

您可以尝试这样做将抄送副本发送到发件人电子邮件

$headers["From"] = "$from";
$headers["To"] = "$email";
$headers["Subject"] = $subject;
$headers['Cc'] = '$from';