Jump to content

inserting custom fields in php email script


Recommended Posts

i got a php script from a website. it works great, however i would like to add a few custom text fields to the email. im pretty new with php, and ive tried a few different things, including following the method used for the other fields in the script, and also to concatenate the different text fields into one variable, both to no avail. would someone be able to point me in the right direction of how to do this? i need to add 3 fields..'Type of Business:' 'Revenue Size of Business:' and 'Financial Goals:'

 

here's the php script

 

mind you, i have tried emailing the developer and got no answer. im trying really hard to learn how to do this, and ive been struggling with this for a week. id appreciate any help given

 

<?php

// Copyright (C) 2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
//     Instead, you may link to the homepage of this code:
//     http://www.php-development.ru/php-scripts/contact-form.php
// (3) Use this code as part of another product.
//
// YOU MAY
// (1) Use this code on your website.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.

?>


<!-- ***** Configuration *************************************************** -->

<?php

$contact_form_field_name    = 'Name:';
$contact_form_field_email   = 'E-mail:';
$contact_form_field_subject = 'Subject:';
$contact_form_field_message = 'Message:';
$contact_form_field_number  = 'Turing number:';
$contact_form_field_prompt  = 'Enter the number displayed above';

$contact_form_button        = 'Submit';

$contact_form_sent          = 'Message sent';
$contact_form_not_sent      = 'Message not sent';
$contact_form_invalid_data  = 'Please, correct the fields marked with red';

?>


<div class="contact_form">


<!-- ***** PHP ************************************************************* -->

<?php

// ***** Functions *****

function contact_form_post($name)
{
  return isset($_POST[$name]) ? htmlentities($_POST[$name], ENT_COMPAT) : '';
}

// ***** Send Mail *****

if (isset($_POST['Contact']))
{
  if (get_magic_quotes_gpc() && !function_exists('strip_slashes_deep'))
  {
    function strip_slashes_deep($value)
    {
      if (is_array($value)) return array_map('strip_slashes_deep', $value);
      return stripslashes($value);
    }

    $_GET    = strip_slashes_deep($_GET);
    $_POST   = strip_slashes_deep($_POST);
    $_COOKIE = strip_slashes_deep($_COOKIE);
  }

  $patern_aux1   = "(\\w+(-\\w+)*)";
  $patern_aux2   = "($patern_aux1\\.)*$patern_aux1@($patern_aux1\\.)+$patern_aux1";

  $valid_name    = isset($_POST['Name'   ]) && trim($_POST['Name'   ]);
  $valid_email   = isset($_POST['Email'  ]) && preg_match("/^$patern_aux2$/iX", $_POST['Email']);
  $valid_subject = isset($_POST['Subject']) && trim($_POST['Subject']);
  $valid_message = isset($_POST['Message']) && trim($_POST['Message']);
  $valid_number  = isset($_POST['Number' ]) && isset($_SESSION['Number']) && $_POST['Number'] == $_SESSION['Number'];

  if (!$valid_name)    $contact_form_field_name    = "<em>$contact_form_field_name   </em>";
  if (!$valid_email)   $contact_form_field_email   = "<em>$contact_form_field_email  </em>";
  if (!$valid_subject) $contact_form_field_subject = "<em>$contact_form_field_subject</em>";
  if (!$valid_message) $contact_form_field_message = "<em>$contact_form_field_message</em>";
  if (!$valid_number)  $contact_form_field_number  = "<em>$contact_form_field_number </em>";

  if ($valid_name && $valid_email && $valid_subject && $valid_message && $valid_number)
  {
    $error_reporting = error_reporting(E_ERROR | E_PARSE);
    $mail_sent = mail($contact_form_your_email,
                      $_POST['Subject'],
                      $contact_form_message_prefix . $_POST['Message'],
                      "To: $contact_form_your_name <$contact_form_your_email>\r\n" .
                      "From: {$_POST['Name']} <{$_POST['Email']}>\r\n");
    error_reporting($error_reporting);

    if ($mail_sent)
         echo "<div class=\"error\"><em>                $contact_form_sent    </em></div>";
    else echo "<div class=\"error\"><em class=\"error\">$contact_form_not_sent</em></div>";
    if ($mail_sent) $_POST = array();
  }
  else echo "<div class=\"contact_form\"><div class=\"error\"><em>$contact_form_invalid_data</em></div></div>";
}

$_SESSION['Number'] = str_pad(rand(0, 9999), 4, '0', STR_PAD_LEFT);

?>


<!-- ***** IE Patch ******************************************************** -->

<!--[if IE]><style type="text/css"> div.contact_form div.input input    { margin-top: -1px; margin-bottom: -1px; } </style><![endif]-->
<!--[if IE]><style type="text/css"> div.contact_form div.input textarea { margin-top: -1px; margin-bottom: -1px; } </style><![endif]-->


<!-- ***** XHTML *********************************************************** -->

<?php if ( $contact_form_xhtml) { ?>

<form method="post" action="<?=$_SERVER['REQUEST_URI'];?>">
<table>

<tr><th><?=$contact_form_field_name;   ?></th><td><div class="input"><input    name=   "Name" type="text" value="<?=contact_form_post(   'Name');?>"        /></div></td></tr>
<tr><th><?=$contact_form_field_email;  ?></th><td><div class="input"><input    name=  "Email" type="text" value="<?=contact_form_post(  'Email');?>"        /></div></td></tr>
<tr><th><?=$contact_form_field_subject;?></th><td><div class="input"><input    name="Subject" type="text" value="<?=contact_form_post('Subject');?>"        /></div></td></tr>
<tr><th><?=$contact_form_field_message;?></th><td><div class="input"><textarea name="Message" cols="35" rows="6"><?=contact_form_post('Message');?></textarea></div></td></tr>

<tr><th><?=$contact_form_field_number;?></th><td>
  <div class="input" style="float: left;"><input type="text" name="Number" autocomplete="off" /></div>
   
  <img width="60" height="17" src="<?=$contact_form_image_url;?>?sname=<?=session_name();?>&rand=<?=rand();?>" alt="" />
  <br style="clear: both" />
  <small><?=$contact_form_field_prompt;?></small>
</td></tr>

<tr><th></th><td><input id="submit_contact" class="submit" type="submit" name="Contact" value="<?=$contact_form_graphic_button ? '' : $contact_form_button;?>" /></td></tr>

</table>
</form>

<?php } ?>


<!-- ***** HTML ************************************************************ -->

<?php if (!$contact_form_xhtml) { ?>

<form method="post" action="<?=$_SERVER['REQUEST_URI'];?>">
<table>

<tr><th><?=$contact_form_field_name;   ?></th><td><div class="input"><input    name=   "Name" type="text" value="<?=contact_form_post(   'Name');?>"         ></div></td></tr>
<tr><th><?=$contact_form_field_email;  ?></th><td><div class="input"><input    name=  "Email" type="text" value="<?=contact_form_post(  'Email');?>"         ></div></td></tr>
<tr><th><?=$contact_form_field_subject;?></th><td><div class="input"><input    name="Subject" type="text" value="<?=contact_form_post('Subject');?>"         ></div></td></tr>
<tr><th><?=$contact_form_field_message;?></th><td><div class="input"><textarea name="Message" cols="35" rows="6"><?=contact_form_post('Message');?></textarea></div></td></tr>

<tr><th><?=$contact_form_field_number;?></th><td>
  <div class="input" style="float: left;"><input type="text" name="Number" autocomplete="off"></div>
   
  <img width="60" height="17" src="<?=$contact_form_image_url;?>?sname=<?=session_name();?>" alt="">
  <br style="clear: both">
  <small><?=$contact_form_field_prompt;?></small>
</td></tr>

<tr><th></th><td><input id="submit_contact" class="submit" type="submit" name="Contact" value="<?=$contact_form_graphic_button ? '' : $contact_form_button;?>"></td></tr>

</table>
</form>

<?php } ?>


</div>

i just know it would be easier to edit this script..can anyone just give me a hint on how to edit the given script? i know there are various tutorials to make your own, but even in my first post i just asked how to edit this...sorry im not that good at it

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.