I recently downloaded AO FormMail from this site and despite my best efforts am completely lost in getting it to work with my form.
I have named all my form elements to match those of the demo form on the AO Mail website other than the fact that I do not have a subject field (ok as is overwritten by a subject setting in the script) but I have an extra "website" element that I want to include in the email that gets sent by the script.
Below is the code for my form and the default code for the AO Mail script, please can someone point out what I need to do to include my "website" field in the script?
Any help is greatly appreciated as this is very time sensitive
<?php
/* ******************************** */
/* Azabia Business Services */
/* www.azabia.co.uk */
/* AO - FormMail Script */
/* */
/* Release Date: 26/03/2008 */
/* Revision Date: 14/04/2008 */
/* Version: 1.01 */
/* ******************************** */
/* Modify these settings below... */
/* ******************************** */
// Set any required fields below. Separate each one with a comma.
$required_fields ="field1,field2,field3";
// Set the URL where you want the user to be redirected to if the submission is successful.
// This can be overridden by having a hidden form field as 'success_url'
$success_url ="http://www.mywebsite.co.uk/success.php";
// Set the URL where you want the user to be redirected to if the submission failed.
// This can be overridden by having a hidden form field as 'failed_url'
$failed_url ="http://www.mywebsite.co.uk/failed.php";
// Set this to 0 to disable sending emails (e.g. you only want to enter it in a database)
$send_email =1;
// Set the email addresses you want the script to email to.
// Assign each email address a number, and in the form make a field called "email_to" and the value being the number.
// If no number is specified, then it will email all the addresses on the list.
$email_to =array( "1" =>"myemail@mywebsite.co.uk",
"2" =>"sales@mywebsite.co.uk");
// If you want to email just one address, comment out the above array and uncomment this one, then specify the email address.
//$email_to ="sales@mywebsite.co.uk";
// Check referrer? Set to 1 to enable (recommended) and specify allowed pages below. Set to 0 to disable.
$check_referrer =1;
// Here you can enter a list of referrers (webpages) that can use your script. You can also turn each one on/off too.
// 1 = on (allowed), 2 = off
$referrer_ok =array( "http://www.mywebsite.co.uk/contactus.php" =>1,
"http://mywebsite.co.uk/contactus.php" =>1,
"http://www.matessite.co.uk/spammer.php" =>0);
// Here are the database settings, set the following value to 1 if you want to input the stored data into the database.
// See the documentation at http://www.azabia.co.uk/phpscripts/ao_formmail.php for information on how this works.
$store_db =0;
// List the form fields (separate by a comma) that you do not want to enter in to the database.
$exclude_fields ="submit,email_to,success_url,failed_url,subject";
$db_username =""; // Username for the database
$db_password =""; // Password for the database
$db_database =""; // Database name
$db_hostname ="localhost"; // Hostname to connect to the database (usually localhost)
$table_name =""; // Name of the table to insert into
// This will form the beginning of the email that is sent (remember to end it in \r\n)
$message ="Here is the result of a form submitted through ".$_SERVER['HTTP_REFERER']."\r\n\r\n";
// This will be the subject of the email that is sent, can be overridden by adding a form field 'subject'.
$subject ="Form Submission Result";
// The name which will appear in the From: field when the email is sent to you (handy for allowing mail)
$from_name ="AO FormMail";
// The email address which will appear in the From: field when the email is sent to you
$email_From ="formmail@mywebsite.co.uk";
/* ******************************** */
/* Stop modifying now... */
/* ******************************** */
function safe_q($value) {
if(get_magic_quotes_gpc()) { $value=stripslashes($value); }
if(function_exists("mysql_real_escape_string")) { $value=mysql_real_escape_string($value); }
else { $value=addslashes($value); }
return $value;
}
$err=0;
if($check_referrer) {
if($referrer_ok[$_SERVER['HTTP_REFERER']]) {
$allowed=1;
}
else {
$allowed=0;
}
}
else {
$allowed=1;
}
if($allowed) {
if($store_db) {
$efields=explode(',',$exclude_fields);
foreach($efields as $a) {
unset($_REQUEST[$a]);
}
$link=mysql_connect($db_hostname, $db_username, $db_password) or die("Unable to connect to Database");
mysql_select_db($db_database,$link) or die("Unable to connect to Database");
$sql="INSERT INTO ".$table_name." (";
$sql2=") VALUES(";
$sql_end=")";
}
$cfields=explode(',',$required_fields);
foreach($cfields as $a) {
if(!$_REQUEST[$a]) { $err++; }
}
$x=0;
foreach($_REQUEST as $a => $b) {
$message.=$a.": ".$b."\r\n";
if($store_db) {
if($x>=1) {
$sql.=", ";
$sql2.=", ";
}
$sql.="`".$a."`";
$sql2.="'".$b."'";
}
$x++;
}
if($store_db) {
$query=$sql.$sql2.$sql_end;
}
if($err) {
if($_REQUEST['failed_url']) {
Header('Location: '.$_REQUEST['failed_url']);
}
elseif($failed_url) {
Header('Location: '.$failed_url);
}
else {
?>
<p align="center"><strong>Your form submission contained errors, please press the back button and try again.</strong></p>
<?php
}
}
else {
if($_REQUEST['subject']) {
$subject=$_REQUEST['subject'];
}
if(is_array($email_to)) {
if($_REQUEST['email_to']) {
if($send_email) {
$email_to=$email_to[$_REQUEST['email_to']];
mail($email_to,$subject,$message,"From: ".$from_name." <".$email_from.">");
}
}
else {
foreach($email_to as $a => $b) {
if($send_email) {
mail($b,$subject,$message,"From: ".$from_name." <".$email_from.">");
}
}
}
}
else {
if($send_email) {
mail($email_to,$subject,$message,"From: ".$from_name." <".$email_from.">");
}
}
if($store_db) {
mysql_query($query) or die("Error adding data to database. Check the table structure.");
mysql_close($link);
}
if($_REQUEST['success_url']) {
Header('Location: '.$_REQUEST['success_url']);
}
elseif($success_url) {
Header('Location: '.$success_url);
}
else {
?>
<p align="center"><strong>Thank you for your form submission.</strong></p>
<?php
}
}
}
else {
?>
<p align="center"><strong>Sorry, the referrer is invalid.</strong></p>
<?php
}
?>
Are you just wanting them to fill out a form that sends you an email?
If so, I think you might using a little more firepower then necessary here.
You could use a small amount of php code to have an email sent from a form.
I do not have time right now to write the code to do it but if this is all you are wanting to do I am sure someone on here will whip you a quick solution or link to one.