php反馈电子邮件表单

时间:2009-07-13 11:43:37

标签: php email forms

您好我正在尝试为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);

?>

哦还有一件事是可以将时间戳更改为亚洲吗? + 8gmt?我的知识在php中很少。谢谢!

2 个答案:

答案 0 :(得分: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

?>

答案 1 :(得分:0)

你可以;

  1. 使用要包含给访问者的文本定义变量$ visitormessage
  2. 添加新的邮件功能调用,例如邮件($ visitormail,$主题,$ visitormessage,从$);