PDA

View Full Version : Urgent HELP!


horse32
04-17-2005, 03:16 PM
Hi
i am just wondering if anyone has code to create a simple contact us page i need to have edit fields where the user can type their message and email address and send it to my own personal email address. Not like a guest book!
any help would be brill!
Cheers!!!

kate
04-17-2005, 03:52 PM
Hya,
You need a mail form thats all, just google 'mailforms'...but you will need PHP to be able to use such a form, best check with your host.

:D

domedia
04-17-2005, 05:33 PM
Actually, you won't need PHP. You *can* use PHP if your server supports it. Find out from you hsot which server-side languages are installed on your server first and then find a mail script that can be used for the language.

horse32
04-17-2005, 05:48 PM
i would like to do it in JSP.. but if not i want something really simple that works!!!

gmcrone
04-17-2005, 06:30 PM
Javascript itself cannot directly send email and you wouldn't want to anyway as it is not secure.

Find out from your host if your server supports ASP or PHP.

Odds are that it supports PHP, as most hosts do.

If true then you can use this php script:

First make your form you want to use and add this line to the beginning of the form:
<FORM action=email.php method=post>

Then the email.php script is this: Change the first 3 lines to your actual site.

<?
$owner_url = "www.mysite.com";
$site_name = "MyWEB site";
$owner_email = "mymail@mysite.com";
$email_subject = "Feedback";
$success_title = "Successful Submission";
$success_msg = "Thank you for your feedback";
$receipt_subject = "Thank You!";
$receipt_body = "Hi
Thank you for completing our feedback form, we'll
get back to you as soon as we can";

$logging = "Y"; // "Y" Adds user details (ip, browser etc) set to "N" if you wish to turn this off

// STYLE SETTINGS
$bgcolor = "#ffffff"; // Page background colour
$font = "verdana"; // Font face
$title_main_colour = "#000000"; // Main Title Colour
$main_colour = "#000000"; // Hex value of font main color
$size = "2"; // Main font size
$title_error_colour = "#ff0000"; // Colour of error title
$error_colour = "#ff0000"; // Colour of error message

// ERROR CHECKING
$error_title = "Error!"; // Error page title
$error_msg = "You missed a required field (click 'back')"; // Error message

// REQUIRED FIELDS
$check = array("owner_email");

// SPAM LOCK

$spam_lock = "Y"; // Turn off at your own risk by changing to $spam_lock = "";

// EDIT PAST THIS POINT AT YOUR OWN RISK!!

if ($spam_lock) {

if (!$PHPSESSID) {
session_start();
}
else {
echo "<html>
<head>
<title></title>
</head>
<body bgcolor=$bgcolor>
<center><h2><font face=$font color=$title_main_colour>Error!</h2>
<font face=$font size=$size color=$main_colour>To protect our network from spam you are only allowed to submit this form once during a visit.

Return to <a href=\"http://$owner_url\">$site_name</a></font>
</center>
</body>
</html>";
exit;
}

}
else {
}
?>

<html>
<head>
<title></title>
</head>
<body bgcolor=<?echo "$bgcolor"; ?>>
<?
$count_array = 0;
do {
$r = $check[$count_array];
if(!$$r) {
echo "<center><h2><font face=$font color=$title_error_colour>$error_title</h2>";
echo "<font face=$font size=$size color=$error_colour>$error_msg</font></center>";
exit;
}
$count_array++;
} while ($count_array != count($check));

$date = date("m/d/Y H:i:s");

$traceroute = "<a href=\"http://www.above.net/cgi-bin/trace?$REMOTE_ADDR\">";

if ($REMOTE_ADDR == "") $ip = " no ip ";
else $ip = getHostByAddr($REMOTE_ADDR);

while(list($key, $val) = each($HTTP_POST_VARS)){
$key = stripslashes($key);
$val = stripslashes($val);
$body .= "$key: $val\n";

}
mail($email,$receipt_subject,$receipt_body,"From:$owner_email");

if ($logging == "N") {
mail($owner_email,$email_subject,$body,"From:$owner_email");
}
else if ($logging == "Y") {
$body .= "\n\nUsing: $HTTP_USER_AGENT";
$body .= "\nHostname: $ip";
$body .= "\nIP address: $REMOTE_ADDR";
$body .= "\nDate/Time: $date";
mail($owner_email,$email_subject,$body,"From:$owner_email");
}
?>
<center>
<h2><font face=<? echo "$font"; ?> color=<? echo "$title_main_colour"; ?>><? echo "$success_title"; ?></font></h2>
<font face=<? echo "$font"; ?> color=<? echo "$title_main_colour"; ?>> <font face=<? echo "$font"; ?> size=<? echo "$size"; ?> color=<? echo "$main_colour"; ?>><? echo "$success_msg"; ?></font>

<font face=<? echo "$font"; ?> size=<? echo "$size"; ?> color=<? echo "$main_colour"; ?>>Return
to "><? echo "$site_name"; ?> (http://<? echo )</font>
</font>
</center>
</BODY>
</html>


Mike....

Jim_Shady
04-18-2005, 01:25 PM
What a great reply Mike - I'll probably use this lot myself at some point in the next few days.

Thanks again - Jim Shady.

Finland Blue
05-30-2005, 06:16 PM
Javascript itself cannot directly send email and you wouldn't want to anyway as it is not secure.

Find out from your host if your server supports ASP or PHP.

Odds are that it supports PHP, as most hosts do.

If true then you can use this php script:

First make your form you want to use and add this line to the beginning of the form:
<FORM action=email.php method=post>

Then the email.php script is this: Change the first 3 lines to your actual site.

<?
$owner_url = "www.mysite.com";
$site_name = "MyWEB site";
$owner_email = "mymail@mysite.com";
$email_subject = "Feedback";
$success_title = "Successful Submission";
$success_msg = "Thank you for your feedback";
$receipt_subject = "Thank You!";
$receipt_body = "Hi
Thank you for completing our feedback form, we'll
get back to you as soon as we can";

$logging = "Y"; // "Y" Adds user details (ip, browser etc) set to "N" if you wish to turn this off

// STYLE SETTINGS
$bgcolor = "#ffffff"; // Page background colour
$font = "verdana"; // Font face
$title_main_colour = "#000000"; // Main Title Colour
$main_colour = "#000000"; // Hex value of font main color
$size = "2"; // Main font size
$title_error_colour = "#ff0000"; // Colour of error title
$error_colour = "#ff0000"; // Colour of error message

// ERROR CHECKING
$error_title = "Error!"; // Error page title
$error_msg = "You missed a required field (click 'back')"; // Error message

// REQUIRED FIELDS
$check = array("owner_email");

// SPAM LOCK

$spam_lock = "Y"; // Turn off at your own risk by changing to $spam_lock = "";

// EDIT PAST THIS POINT AT YOUR OWN RISK!!

if ($spam_lock) {

if (!$PHPSESSID) {
session_start();
}
else {
echo "<html>
<head>
<title></title>
</head>
<body bgcolor=$bgcolor>
<center><h2><font face=$font color=$title_main_colour>Error!</h2>
<font face=$font size=$size color=$main_colour>To protect our network from spam you are only allowed to submit this form once during a visit.

Return to <a href=\"http://$owner_url\">$site_name</a></font>
</center>
</body>
</html>";
exit;
}

}
else {
}
?>

<html>
<head>
<title></title>
</head>
<body bgcolor=<?echo "$bgcolor"; ?>>
<?
$count_array = 0;
do {
$r = $check[$count_array];
if(!$$r) {
echo "<center><h2><font face=$font color=$title_error_colour>$error_title</h2>";
echo "<font face=$font size=$size color=$error_colour>$error_msg</font></center>";
exit;
}
$count_array++;
} while ($count_array != count($check));

$date = date("m/d/Y H:i:s");

$traceroute = "<a href=\"http://www.above.net/cgi-bin/trace?$REMOTE_ADDR\">";

if ($REMOTE_ADDR == "") $ip = " no ip ";
else $ip = getHostByAddr($REMOTE_ADDR);

while(list($key, $val) = each($HTTP_POST_VARS)){
$key = stripslashes($key);
$val = stripslashes($val);
$body .= "$key: $val\n";

}
mail($email,$receipt_subject,$receipt_body,"From:$owner_email");

if ($logging == "N") {
mail($owner_email,$email_subject,$body,"From:$owner_email");
}
else if ($logging == "Y") {
$body .= "\n\nUsing: $HTTP_USER_AGENT";
$body .= "\nHostname: $ip";
$body .= "\nIP address: $REMOTE_ADDR";
$body .= "\nDate/Time: $date";
mail($owner_email,$email_subject,$body,"From:$owner_email");
}
?>
<center>
<h2><font face=<? echo "$font"; ?> color=<? echo "$title_main_colour"; ?>><? echo "$success_title"; ?></font></h2>
<font face=<? echo "$font"; ?> color=<? echo "$title_main_colour"; ?>> <font face=<? echo "$font"; ?> size=<? echo "$size"; ?> color=<? echo "$main_colour"; ?>><? echo "$success_msg"; ?></font>

<font face=<? echo "$font"; ?> size=<? echo "$size"; ?> color=<? echo "$main_colour"; ?>>Return
to "><? echo "$site_name"; ?> (http://<? echo )</font>
</font>
</center>
</BODY>
</html>


Mike....
This sounds just what I need but ... could you please help a new and stupid user (ie, ME!) exactly what to copy and paste where ... is some in the form itself, and some in the head (ie, like a java script)?

Thanks!

gmcrone
05-30-2005, 07:52 PM
In your page with the contact form add this to the form that you have written:
<FORM action=email.php method=post>

The rest of the script is saved as a file called email.php
This file needs to go be uploaded to your site in the same place as your form page.

Mike...

Finland Blue
05-31-2005, 01:05 PM
Thanks Mike - I got the form to work in that it sent me the email, but at the same time gave some error messages to the user - anyhow, I got my ISP to provide me a link to their formmail, and that did the trick.

Thanks anyway ... :)