Page 1 of 1
sending form to email
Posted: Tue May 06, 2008 5:15 am
by t3h_vagrant
ok so lets say that i dont know much about php but here goes. im making this website with some forms in it. i need to know how to send the filled information to my email. any example or tutorial or template would be useful! thenks!
Re: sending form to email
Posted: Tue May 06, 2008 5:40 am
by Kadanis
If you want very basic, I suggest you look up the mail() function on php.net
If you want more advanced, have a look at Swift mail. There is a dedicated forum on this site for Swift as the author is one of the contributors here.
mail() will offer you basic plaintext mails, Swift can offer you full HTML, mail merge and loads more. Have a look at both and see which covers your needs.
As for the form stuff, I've included some very basic examples below. You'll obviously need to pad these out to suit.
Code: Select all
<!-- Very basic form for mailing. Put this in mail.htm -->
<html>
<head />
<body>
<form name="mailer" method="post" action="mail.php">
To: <input name="to" value="" type="text" /><br />
Subject: <input name="subject" value="" type="text" /><br />
Message: <textarea name="message" />
<input type="submit" value="Send" />
</form>
</body>
</html>
Code: Select all
<?php
#mail.php
#get the form variables from the super-global
#sets the variables to null if they are not picked up from the form
$to = (isset($_POST['to'])) ? $_POST['to'] : null;
$subject = (isset($_POST['subject'])) ? $_POST['subject'] : null;
$message = (isset($_POST['message'])) ? $_POST['message'] : null;
$from = 'myfromaddress@mydomain.tld';
if (!is_null($to) && !is_null($subject) && !is_null($message)){
#insert mail code here using either Swift or mail()
} else {
#error handling
}
?>