【问题标题】:how to send php form data to user also owner? [closed]如何将php表单数据发送给用户也是所有者? [关闭]
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

    【解决方案2】:

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

    【讨论】:

    • Bcc 进行密件复制
    • 发件人已将表单数据发送给网站所有者,但无法发送用户电子邮件地址。
    • 你在 mail() 函数中使用过标头吗?请更新问题中的代码。
    • 我使用了它,但它没有向用户电子邮件发送数据。
    • 请用您正在使用的代码更新问题。
    猜你喜欢
    • 2023-03-29
    • 1970-01-01
    • 2013-05-16
    • 2013-09-19
    • 2012-09-14
    • 2013-08-23
    • 1970-01-01
    • 2022-08-19
    • 2014-10-12
    相关资源
    最近更新 更多