【问题标题】:php feedback email formphp反馈邮件表单
【发布时间】:2009-07-13 11:43:37
【问题描述】:

您好,我正在尝试为 php 制作一个反馈表单并且它有效,但我只是想知道,我可以制作一组代码也将这封电子邮件发送给发送这封邮件的访问者吗?还标记了一条小消息,例如“谢谢您的反馈。这是您写的消息“.....”。这是我的代码:

<?php

$myemail = "****@myemail.com"; 
$ccx = ""; 

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) 
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n"; 
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}
echo $badinput;

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn . "(" . $ccopy . ")" ; 
$subject = $attn; 

$notes = stripcslashes($notes); 

$message = " $todayis \n
From: $visitor ($visitormail)\n
Website URL: $weburl \n
Message: $notes \n 
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";

if (($ccopy == "ccyes") && ($visitormail != "")) 
mail($visitormail, $subject, $message, $from);

if ($myemail != "") 
mail($myemail, $subject, $message, $from);

if ($ccx != "") 
mail($ccx, $subject, $message, $from);

?>

哦,还有一件事可以将时间戳更改为亚洲吗? +8 格林威治标准时间?我对php的了解很少。谢谢!

【问题讨论】:

  • 不要这样做。您允许任意访问者将您的电子邮件发送到任意电子邮件地址。垃圾邮件发送者喜欢这个。
  • 说真的,不要这样做!大卫·多沃德是绝对正确的。

标签: php email forms


【解决方案1】:

示例代码

此功能缺乏任何健全性检查/验证,但我希望它可以为您提供一个起点:

<?php

# sends feedback information to an array of recipient email addresses.
# an email is also sent to the users email address.
function send_feedback_emails($mail_body, $recipients = array(), $user_email = false)
{
    $recipients = implode("; ", $recipients);
    $mail_headers = "From: <feedback@example.com>";
    $mail_subject = "example.com - Feedback Form - " . date("c");

    # send it to the recipients.
    mail($recipients, $mail_subject, $mail_body, $mail_headers);

    # send it to the user with a slightly diffrent message.
    if ($user_email != false) {
        $mail_body = "Thank you, for your feedback!\n" .
                     "Below is a copy of your feedback information...\n\n" .
                     $mail_body;
        mail($user_email, $mail_subject, $mail_body, $mail_headers);
    }
}

# get the data from your form, I'll fake it here...
$feedback_data["name"] = "Luke Antins";
$feedback_data["email"] = "luke@lividpenguin.com";

# building the feedback message template.
$mail_template = <<<EOL
FEEDBACK FORM
=============
Date Received: %s
Name: %s
Email: %s

EOL;

# puts information into the template.
$mail_body = sprintf($mail_template, date("c"), $feedback_data["name"],
                     $feedback_data["email"]);

# build an array of emails you want this message to be sent to.
$recipients[] = "you@yourdomain.com";
$recipients[] = "bill@microsoft.com";

# lets try out our send_feedback_emails function!
send_feedback_emails($mail_body, $recipients, $feedback_data["email"]);

?>

时区

要使日期/时间函数使用特定时区,您可以使用date_default_timezone_set()

<?php

date_default_timezone_set("Asia/Katmandu");
echo date("c"); # example output (ISO 8601 format): 2009-07-13T17:55:53+05:45

?>

【讨论】:

  • 因为我的代码有这部分 $message = " $todayis [EST] \n 我想知道它可以改为亚洲时间而不使用 EST 吗?
  • 如果你使用 date_default_timezone_set() 方法,它会在你这样做时使用那个时区 $todayis = date("l, F j, Y, g:i a"); 我在示例中使用了 date("c");,因为它在其输出中显示了时区偏移量。
  • 我遇到了致命错误。它不起作用。致命错误:调用未定义函数:第 26 行 /home/virtual/xxxxxxxx/sent2.php 中的 date_default_timezone_set() 我所做的只是添加 date_default_timezone_set("Asia/Katmandu");
  • date_default_timezone_set() 需要 PHP >= 5.1.0,尝试使用 putenv("TZ=Asia/Katmandu");
  • 啊,好吧,但我不能使用 putenv("TZ=Asia/Katmandu");因为有安全模式..我想没关系。谢谢哥们!
【解决方案2】:

你可以;

  1. 定义一个变量 $visitormessage,其中包含您要包含给访问者的文本
  2. 添加新的邮件函数调用,例如邮件($visitormail,$subject,$visitormessage,$from);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 2018-01-28
    相关资源
    最近更新 更多