【发布时间】:2014-08-31 13:24:20
【问题描述】:
我有一个 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();
}
?>
【问题讨论】:
标签: php jquery html forms email