Web Form That's Submitted To An Email Address

A Member? Please Login  
type your username and password to login
Date: July 26, 2008, 01:04 AM
223714 members and 127026 Topics
Latest Member: gtnogvvizz
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Web Form That's Submitted To An Email Address
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Web Form That's Submitted To An Email Address  (Read 434 views)
chinesedoll (f)
Web Form That's Submitted To An Email Address
« on: May 26, 2006, 10:29 AM »

Hi guys anybody here who can give me a code
whereby if a form is submitted it goes to an
email address instead of a database

It could be  PHP
C# OR ASP.NET.

i NEED IT URGENTLY.
tundeajiba (m)
Re: Web Form That's Submitted To An Email Address
« #1 on: May 26, 2006, 01:56 PM »

visit this site http://www.boaddrink.com
IAH (f)
Re: Web Form That's Submitted To An Email Address
« #2 on: May 26, 2006, 02:00 PM »

Google "php form emailer script" or "asp form emailer script". You’ll find free ones to lift. Smiley
Zahymaka (m)
Re: Web Form That's Submitted To An Email Address
« #3 on: May 26, 2006, 03:24 PM »

ruky_ivy, from a previous post of yours, I assume you're more comfortable with Asp.NET. I'm more inlined towards C# but I'll give you the code in both C# and VB.

C#

using System.Web.Mail; // the .NET mail namespace

MailMessage myMailMsg = new MailMessage();
myMailMsg.Subject = "Subject of Mail";
myMailMsg.To = "recipient@example.com";
myMailMsg.From = "sender@example.com";
// you can add myMailMsg.Cc and myMailMsg.Bcc
myMailMsg.BodyFormat = MailFormat.Text; // can be either MailFormat.Text or MailFormat.HTML
myMailMsg.Priority = MailPriority.Normal; //can be either MailPriority.High, MailPriority.Normal or MailPriority.Low
myMailMsg.Body = "your body"; // you can append the body from a textbox eg myMailMsg.Body = txtComments.Text;

SmtpMail.Send(myMailMsg); // send message




VB

Imports System.Web.Mail ' the .NET mail namespace

Dim myMailMsg as MailMessage = new MailMessage
myMailMsg.Subject = "Subject of Mail"
myMailMsg.To = "recipient@example.com"
myMailMsg.From = "sender@example.com"
'you can add myMailMsg.Cc and myMailMsg.Bcc
myMailMsg.BodyFormat = MailFormat.Text 'can be either MailFormat.Text or MailFormat.HTML
myMailMsg.Priority = MailPriority.Normal 'can be either MailPriority.High, MailPriority.Normal or MailPriority.Low
myMailMsg.Body = "your body" 'you can append the body from a textbox eg myMailMsg.Body = txtComments.Text

SmtpMail.Send(myMailMsg) 'send message


As you can see, the code is very similar.
It's been long since I did anything Asp.NET but if you run into any snags [especially exceptions] you can always reply here.

smartsoft (m)
Re: Web Form That's Submitted To An Email Address
« #4 on: May 29, 2006, 09:55 AM »


Step 1:: Make a page called contact.php and paste this code into it.

Code:
<form action="contactme.php" mehod="post">
<p align="center">
<b><font size="2" face="Verdana">Name: <input type="text" name"username" size="30"/>
<br>
<br>
Email: <input type="text" name="useraddr" size="30">
<br>
<br>
Message: <textarea name="comments" cols="30" rows="5"> </textarea>
<br>
<br>
<input type="submit" value="Send Form"> </font></p>
</form></b>

Step 2:: Make a new page and paste the code below into it and name it contactme.php
Code:
<?PHP
#Where you want the email to go
$to = "Youremail@yoursite.com";

#subject of the message, change this
$re = "Feedbackfromcontactpage";

#message from the feedback form, don't touch this
$msg = $comments;

#send the mail, don't edit this
mail($to,$re,$msg);
header("location: thankyou.htm");
?>
Zahymaka (m)
Re: Web Form That's Submitted To An Email Address
« #5 on: May 29, 2006, 12:44 PM »

smartsoft, I'm sure you didn't mean to make a mistake but using $comments instead of $_POST['comments'] in PHP only works if register_globals is turned to On.
skima (m)
Re: Web Form That's Submitted To An Email Address
« #6 on: May 30, 2006, 01:52 PM »

Am very sure he must be coding with register_global=on.

But this is not advisible.

Enhanced code : works in any environment that supports php and support sendmail.
Code:
<?PHP
#Where you want the email to go
$to = $_POST['useraddr'];

#subject of the message, change this
$re = "Feedbackfromcontactpage";
/*
*@header : this will show when the user click the reply button in the email client
*/
$header="From: Your own name<youremail@yoursite.com>\r\n";
$header.="Reply-to:<yourreplyemail@yourcompany.com>\r\n";


#message from the feedback form, don't touch this
$msg = $_POST['comments'];

//CHECK TO MAKE SURE THE EMAIL IS VALID

if(!preg_match("/^[^\s()<>@,;:\"\/\[\]?=]+@\w[\w-]*(\.\w[\w-]*)*\.[a-z]{2,}$/i",$email)){
echo "Enter a valid email address";

}else{
//if the email was valid lets send it

#send the mail, don't edit this
if(mail($to,$re,$msg,$header)){

echo " Your email has been sent! to $to.";
}else{
echo "<p> Error sending mail!</p>";
}//end sending email

}//end validate email

?>
smartsoft (m)
Re: Web Form That's Submitted To An Email Address
« #7 on: May 31, 2006, 12:08 PM »

i just knew that my register_global is kind of on, i better stop doing that hey bravo everybody who notice that
 My Programming Skills (J. C. Ozochi)  Web based Pharmaceutical Sales Management System. Help!  Get Ccna Certified In 5 Days !  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Jobs (2) Career Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.