flexible reusable mail script?

Soldato
Joined
19 Oct 2002
Posts
3,480
hi guys...

i would like a php mail script that can accept any amount of feilds (maybe in an array) and do some basic error checking on the email and the like. this i could use for all my websites and it would pass back feedback on errors or success etc...

i could write it myself i guess but i assume its a dead common thing so why rebuilt the wheel?

anyone know where i could get such a script?
 
http://www.w3schools.com/PHP/php_mail.asp

http://www.w3schools.com/PHP/php_secure_mail.asp

Code:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ; 
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail( "[email protected]", "Subject: $subject",
  $message, "From: $email" );
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>

Even with basic PHP knowledge, it's pretty easy to modify the above to suit your needs.
 
Actually, interesting you said this, I have been looking at doing automated forms recently, and even my friend who is a master .NET programmer for a big commercial company says that there really isn't a standardised way of doing this stuff. You still end up having to manually code the form each time, the backend each time (though in .NET's case it automatically does some things for you).

And of course, if you want to do things nicely in a framework like Joomla or have some kind of standardised design framework (MVC model-view-controller for example) you end up having to code everything by hand - a pain in the butt!

I have an idea for a general solution but haven't coded it yet :) But basically it is

1) xml structure + optional validation regular expressions
2) automatic form generation with optional client side/server side validation using the associated regular expressions
3) Optional server side emailing / database storage, structure of database based on the xml structure
4) A nice front end that allows me to create the xml structure and set the entire thing in motion.

Then all I need to create a new web form is fill in the front end along with options, it automatically creates the structure which is then used to create the front end (along with templates) and optional validation, back end and potential database. All from filling in a simple form. And no real programming apart from regular expressions for validation, and only if required.

Design patterns could then be applied to this process... so you still don't have to program anything but you automatically get standardised structure etc and seperates out information/processing by domain etc. It might sound a little overkill but essentially it means no-one would have to go back to coding crappy web forms by hand.

EDIT : And for simplicity, a set of valid regular expressions could be generated in advance to validate things like email, telephone numbers in specific countries, etc etc.
 
Back
Top Bottom