4

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

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

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;
}

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

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

4

5 回答 5

4

那将是

$headers .= 'Cc: anotheremail@domain.net' . "\r\n";
于 2013-09-27T13:28:59.540 回答
2

希望这可以帮助

<?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;            
?>
于 2015-04-22T10:22:26.377 回答
1

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

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

于 2013-09-27T13:28:50.983 回答
0

你可以通过写作来做到这一点

$emailTo = 'owner@website.com, customer@website.com';
于 2013-09-27T13:29:17.283 回答
-2

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

$headers["From"] = "$from";
$headers["To"] = "$email";
$headers["Subject"] = $subject;
$headers['Cc'] = '$from';
于 2013-09-27T13:34:37.013 回答