Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,858 members, 7,802,750 topics. Date: Friday, 19 April 2024 at 08:43 PM

Web Form That's Submitted To An Email Address - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Web Form That's Submitted To An Email Address (1509 Views)

Who's In Need Of An Email Processing Job? / Is There An Email To Sms Gateway Service From Airtel, Glo, Mtn Or Etisalat? / How To Make A Checkbox Required On An Email Form Read More (2) (3) (4)

(1) (Reply) (Go Down)

Web Form That's Submitted To An Email Address by chinesedoll(f): 10:29am On May 26, 2006
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.
Re: Web Form That's Submitted To An Email Address by tundeajiba(m): 1:56pm On May 26, 2006
visit this site http://www.boaddrink.com
Re: Web Form That's Submitted To An Email Address by IAH(f): 2:00pm On May 26, 2006
Google "php form emailer script" or "asp form emailer script". You’ll find free ones to lift. smiley
Re: Web Form That's Submitted To An Email Address by Zahymaka(m): 3:24pm On May 26, 2006
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.
Re: Web Form That's Submitted To An Email Address by smartsoft(m): 9:55am On May 29, 2006
Step 1:: Make a page called contact.php and paste this code into it.

<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
<?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"wink;
?>
Re: Web Form That's Submitted To An Email Address by Zahymaka(m): 12:44pm On May 29, 2006
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.
Re: Web Form That's Submitted To An Email Address by skima(m): 1:52pm On May 30, 2006
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.
<?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

?>
Re: Web Form That's Submitted To An Email Address by smartsoft(m): 12:08pm On May 31, 2006
i just knew that my register_global is kinda on, i better stop doing that hey bravo everybody who notice that

(1) (Reply)

Need A Free Integrated C/C++ Compiler / Creating Mobile Apps As A Tool For Creating More Job In Nigeria / Here Are 8 Amazing Uses Of Java!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 27
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.