如何将PHP表单数据发送给用户也是所有者?

时间:2014-07-10 08:40:16

标签: php jquery html forms email

我有一个php电子邮件表单。当用户填写表单并单击“提交”按钮时,数据已经是网站所有者的eimail地址,但我希望数据也会转到用户的电子邮件地址。请检查并尽快帮助我。这是我的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();
}
?>

2 个答案:

答案 0 :(得分:4)

在标题中使用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);

答案 1 :(得分:0)

只需使用您的电子邮件地址而不是用户的电话向mail添加另一个电话:

mail('your@emailaddress.com',$subject,$message)