Page 1 of 1

Form to email code...

Posted: Sun Nov 15, 2009 7:36 am
by HTF
Hello,

Welcome everybodey as I'm new on this forum.

I have a few question regarding php code - form to email

1. I was testing a lot of php scripts and I have one that it's working now but unfortunately only with my domain email account but it's not with google acount or any other as I receive error:
PHP Warning: mail(): SMTP server response: 550 5.7.1 Unable to relay for email@google.com in C:.....
- this is big problem for me as I would like to use my gemail account

How can I solve this?

2. How to prevent users from refreshing the form after it has been sent so I wouldn't receive more that one emails, I placed something like this in the php code:

Code: Select all

$stopRefresh = true;


- but it didn't help

3. How to set image veryfication, is it a lot of work?

The whole code is belowe and one more questions how it's work as I had to add all form fields IDs to all scripts that I tested before but this one picks up any form...

Code: Select all

<?php
 
error_reporting(E_ALL ^ E_NOTICE);
 
 
$my_email = "email";
 
 
$from_email = "email";
 
 
$continue = "/";
 
 
$errors = array();
 
// Remove $_COOKIE elements from $_REQUEST.
 
if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
 
 
// Display any errors and exit if errors exist.
 
if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
 
if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}
 
// Build message.
 
function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
 
$message = build_message($_REQUEST);
 
$message = stripslashes($message);
 
$subject = "Dark space Quary...";
 
$subject = stripslashes($subject);
 
if($from_email)
{
 
$headers = "From: " . $from_email;
$headers .= PHP_EOL;
$headers .= "Reply-To: " . $_REQUEST['email'];
 
}
else
{
 
$from_name = "";
 
if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}
 
$headers = "From: {$from_name} <{$_REQUEST['email']}>";
 
}
 
mail($my_email,$subject,$message,$headers);
 
$stopRefresh = true; //false; //true;
 
?>
 
 
<html>
<head>
<title>Homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
   background-color: #f1f1f1;
   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-size: 12px;
   font-style: normal;
   line-height: normal;
   font-weight: normal;
   color: #666666;
   text-decoration: none;
}
-->
</style>
</head>
 
<div>
  <div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
</body>
</html>
thanks for any help in advance.

Reg

Re: Form to email code...

Posted: Sun Nov 15, 2009 8:11 am
by jefffan24
http://recaptcha.net/ They make good image verification programs, they also give you all the code and instructions to add to your code, not hard.

$stopRefresh is not a global variable, it is one that you made. I don't know how to stop somebody from refreshing other then redirecting them to another page so like:

if(isset($_POST['submit'])){
header ("location: example.php");
}

What that will do is if somebody pushes your submit (or whatever you have set as the name), then it will redirect them to another page.

I don't know about the email thing.

Re: Form to email code...

Posted: Sun Nov 15, 2009 10:19 am
by HTF

Code: Select all

if(isset($_POST['submit'])){
header ("location: example.php");
}
 
Thx for help this works great, regarding gmail I think it's authentication problem but I dont know how to solve this :?

- one more thing, I can set more than one emails as a recipients but do you know script that when people choose different department from the scroll down list in the form, an email will be sent acording of their choice

Reg