Click to See Complete Forum and Search --> : ASP contact form query


Spyderman
05-13-2010, 04:21 AM
Hi All,

I was recently asked by work to put together a contact form to email page on our site.

So fair enough I thought pretty easy, so I coded one in php. Only to findout when testing it that our site is on a windows server. And does not like PHP!!

So I am going to have to code it again now in .asp which I will say I have little experience in. Now I know I could easily google a script and download it.

But my problem comes when I will have to customise the code to my needs, i need someone to explain how I change the way the emailBody is output/formatted?

Because the actual form I have to come up with has to have multiple fields, with their values being displayed within the emailBody. And so far the examples I have seen online have been basic dealing simply with Name, Email and Message.

Below is a snippet of code from my original files if someone is willing to take a look to see how it needs outputting. You see i understand the concept of how the PHP file gets the info using id's and arrays.

But looking at asp it seems a bit general not sure how to define values.

Thanks

<h3>Entrant Details:</h3>
<form method="post" name="myemailform" action="http://www.moneymedia.co.im/paform-to-email.php">
<p>
<label for='entrant-name'>Name: </label><br>
<input type="text" name="entrant-name" size="40">
</p>
<p>
<label for='entrant-company'>Company:</label><br>
<input type="text" name="entrant-company" size="40">
</p>
<p>
<label for='entrant-position'>Position: </label><br>
<input type="text" name="entrant-position" size="40">
</p>
<p>
<label for='entrant-email'>Contact Email:</label><br>
<input type="text" name="entrant-email" size="40">
</p>
<p>
<label for='entrant-phone'>Contact Telephone Number:</label><br>
<input type="text" name="entrant-phone" size="40">
</p>

<h3>Nominee Details:</h3>
<p>
<label for='nominee-name'>Name:</label> <br>
<input type="text" name="nominee-name" size="40">
</p>
<p>
<label for='nominee-company'>Company:</label><br>
<input type="text" name="nominee-company" size="40">
</p>
<p>
<label for='nominee-position'>Position: </label><br>
<input type="text" name="nominee-position" size="40">
</p>
<p>
<label for='values-message'>What values do you/your PA bring to your organisation?</label> <br>
<textarea name="values-message" cols="40" rows="5"></textarea>
</p>
<p>
<label for='why-message'>Why do you think you/your PA should win the PA of the Year Award?</label> <br>
<textarea name="why-message" cols="40" rows="5"></textarea>
</p>
<input type="submit" name='submit' value="submit">
</form>

<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$entrant_name = $_POST['entrant-name'];
$entrant_position = $_POST['entrant-position'];
$entrant_company = $_POST['entrant-company'];
$entrant_email = $_POST['entrant-email'];
$entrant_phone = $_POST['entrant-phone'];
$nominee_name = $_POST['nominee-name'];
$nominee_position = $_POST['nominee-position'];
$nominee_company = $_POST['nominee-company'];
$values_message = $_POST['values-message'];
$why_message = $_POST['why-message'];

//Validate first
if(empty($entrant_name)||empty($entrant_email))
{
echo "Name and email are mandatory!";
exit;
}

if(IsInjected($entrant_email))
{
echo "Bad email value!";
exit;
}

$email_from = 'richard.brown@manninmedia.co.im';//<== update the email address
$email_subject = "PA of the Year Award - Application";
$email_body = "You have received a new message from $entrant_name, $entrant_position at $entrant_company.\n".
"You can contact me via email at: $entrant_email, or by phone on: $entrant_phone.\n".
"Application:\n".
"I $entrant_name, $entrant_position of $entrant_company. Wish to nominate my PA: $nominee_name for the PA of the Year Award.\n".
"What values does my PA bring to the organisation?\n $values_message\n".
"Why I think my PA should win the PA of the Year Award?\n $why_message\n".
"Nominee Contact Details:\n".
"Name: $nominee_name\n".
"Company: $nominee_company\n".
"Position: $nominee_position\n".;

$to = "richard.brown@manninmedia.co.im";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $entrant_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: http://www.moneymedia.co.im/paform/thank-you.html');


// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

?>

yamaharuss
05-13-2010, 03:50 PM
So you made no attempt at what you found via Google?

Maybe if you made just a little effort we can help with the tougher parts but it sounds like you want us to write your code for you.