tags:

views:

234

answers:

2

Hi I'm trying to make a feed back form for php and it worked but I was just wondering, can i make a set of code also deliver this email to the visitor who sent this mail? Also tagged along with a small message like "Thank you, for your feedback. This is the message you wrote ".....". and here is my code:

<?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);

?>

Ohh one more thing is it possible to change the timestamp to asia? +8gmt? I my knowledge is pretty little in php. Thanks!

A: 

You could;

  1. define a variable $visitormessage with the text you want to include to the visitor
  2. add new mail function call e.g. mail($visitormail,$subject,$visitormessage,$from);
David
Thanks! That's a great help!!!
+1  A: 

Example Code

This function is lacking any sanity checks/validation, but I hope it gives you a place to start:

<?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: <[email protected]>";
    $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"] = "[email protected]";

# 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[] = "[email protected]";
$recipients[] = "[email protected]";

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

?>

Time Zone

To make date/time functions use a specific time zone you could use 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

?>
Luke Antins
Because my code have this part$message = " $todayis [EST] \nI was wondering can it change to asia time and not use EST?
If you use the date_default_timezone_set() method it will use that time zone when you do **$todayis = date("l, F j, Y, g:i a");**I used **date("c");** in my example as it shows the time zone offset in its output.
Luke Antins
I got fatal error on it. It doesn't work.Fatal error: Call to undefined function: date_default_timezone_set() in /home/virtual/xxxxxxxx/sent2.php on line 26all i did was add date_default_timezone_set("Asia/Katmandu");
You need PHP >= 5.1.0 for date_default_timezone_set(), try taking a look at using **putenv("TZ=Asia/Katmandu");**
Luke Antins
Ahh alright but I can't use putenv("TZ=Asia/Katmandu"); because there is safe mode.. I guess it's alright. Thanks buddy!