如何将php表单数据发送给用户和所有者?

如何将php表单数据发送给用户和所有者?,php,jquery,html,forms,email,Php,Jquery,Html,Forms,Email,我有一个php电子邮件表单。当用户填写表单并单击“提交”按钮时,数据已经转到网站所有者的电子邮件地址,但我希望数据也转到用户的电子邮件地址。请检查一下并尽快帮助我。这是我的php代码 <?php /* Set e-mail recipient */ $myemail = "mymail@gmail.com"; $headers = "From: $from\r\n"; $headers .= "Cc: $cc" . "\r\n"; $headers .= "Content-type

我有一个php电子邮件表单。当用户填写表单并单击“提交”按钮时,数据已经转到网站所有者的电子邮件地址,但我希望数据也转到用户的电子邮件地址。请检查一下并尽快帮助我。这是我的php代码

 <?php
/* Set e-mail recipient */
$myemail = "mymail@gmail.com";
$headers  = "From: $from\r\n";
 $headers .= "Cc: $cc" . "\r\n";
 $headers .= "Content-type: text/html\r\n";
 mail($to, $subject, $message, $headers);

/* Check all form inputs using check_input function */
$name = check_input($_POST['inputName'], "Your Name");
$email = check_input($_POST['inputEmail'], "Your E-mail Address");
$message = check_input($_POST['inputMessage'], "Your Message");

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */

$subject = "Someone has sent you a message";

$message = "

Someone has sent you a message using your contac form:

Name: $name
Email: $email

Message:
$message

";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: http://www.editorstable.com/thanks.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>

</body>
</html>
<?php
exit();
}
?>
只需使用您的电子邮件地址而不是用户的电子邮件地址添加另一个call to mail:

邮寄your@emailaddress.com“,$subject,$message

在标题中使用CC

$to = 'myemail@gmail.com';
$from = "from@gmail.com"; // sender
$cc = 'cc@gmail.com';

$subject = "Someone has sent you a message";
$message = 'Your message here';

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
// Additional headers
$headers .= "From: <$from>" . "\r\n";
$headers .= "Cc: $cc" . "\r\n";

// Mail it
mail($to, $subject, utf8_decode($message), $headers);

您不需要调用函数两次。发件人已将表单数据发送给网站所有者,但不用于发送用户电子邮件地址。或者密件抄送收件人已将表单数据发送给网站所有者,但不用于发送用户电子邮件地址。您是否使用了邮件功能中的标题?请更新问题中的代码。我使用了它,但它没有向用户电子邮件发送数据。请使用您正在使用的代码更新问题。