Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向发件人发送电子邮件副本PHP联系人脚本_Php_Email - Fatal编程技术网

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

向发件人发送电子邮件副本PHP联系人脚本,php,email,Php,Email,我正在使用下面的PHP脚本从我的联系人表单中获取电子邮件。我想把同一封邮件的副本也发送给发件人。我该怎么做。。。有人能给我的脚本加几行吗 我可以在$emailTo中分隔多封电子邮件吗owner@website.com,$email' if(!isset($hasError)) { $emailFrom = 'smptcontactemail@website.com'; $emailTo = 'owner@website.com'; $subject = 'Submitt

我正在使用下面的PHP脚本从我的联系人表单中获取电子邮件。我想把同一封邮件的副本也发送给发件人。我该怎么做。。。有人能给我的脚本加几行吗

我可以在$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;
}
if(!isset($hasError)){
$emailFromsmptcontactemail@website.com';
$emailTo=owner@website.com';
$subject='从'.$name'提交的邮件;
$sendCopy=trim($_POST['sendCopy']);
$body=“Name:$Name\n\nEmail:$email\n\n注释:$comments”;
$headers='发件人:'.'\r\n'.'回复:'.$email;
邮件($emailTo、$subject、$body、$headers);
//将布尔完成值设置为TRUE
$emailSent=true;
}
添加另一个函数可能会起作用。但我正在寻找在相同函数中实现这一点的其他简单方法:)

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

参见示例4,了解如何扩展
$additional\u headers
参数以添加抄送收件人:

$headers='From:''。“\r\n”。”答复:"$电子邮件。“\r\n”。”抄送:‘’

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

你可以通过写作来做到

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

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

$headers["From"] = "$from";
$headers["To"] = "$email";
$headers["Subject"] = $subject;
$headers['Cc'] = '$from';
希望这有帮助

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


我想再给发件人发几行。像您的电子邮件副本或其他东西……在这种情况下,您需要发送两封单独的邮件,并因此两次调用mail()。内置的PHP
mail()
函数严重缺乏功能,另外,一旦您开始编写自己的邮件头,安全性往往是一个问题(您的代码可能很容易被黑客攻击以发送垃圾邮件)。因此,我强烈建议在编写PHP程序发送电子邮件时使用像样的mailer类,如PHPMailer或Swiftmailer。@Spudley感谢您的建议。我会调查的!mail()需要一个字符串,而不是数组作为附加参数。这个概念是正确的,但代码不是。您需要附加它。请参见Alma Do Mundo的答案