Email Form - Very Simple

Pages: 1, 2
free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Email Form - Very Simple

shadowx
You can also modify the script as a feedback form and this prevents spambots from finding an email address in the usual mailto way:

QUOTE
comments? email me at imgonnagetspammed@mail.com


The only thing you should be careful of using this script is it doesnt have flood protection. I would set up some kind of timing system so that one person cant send emails for 30 seconds or something otherwise it could be used for abuse. You could do that just by sending a cookie with a life of 30 seconds and then check if the cookie exsists and if it doesnt let them email. otherwise its a very good script smile.gif

Reply

masterio
Based on shadowx suggestion, I modified the script, so only one email than can send in 1 second.

File mymail.php

CODE
<?php

$act = $_GET['act'];  // get act from URL

switch ($act) {
  case default:
    // this case is for showing form
?>
    <form action="mymail.php?act=process" method="post">
     Subject: <input type="text" name="subject" size="75" /><br />
     From: <input type="text" name="from" value="your@email.com" />
     To: <br />
     <textarea name="to" cols="55" rows="5"></textarea>
     Message: <br />
     <textarea name="message" cols="55" rows="10"></textarea><br />
    <input type="submit" value="Send!" />
    </form>
<?php
    
  break;

  case 'process':
     $subject = $_POST['subject'];
     $from = $_POST['from'];
     $to = $_POST['to'];
     $message = $_POST['message'];

     // check all the fields first
     if (empty($subject) || empty($from) || empty($to) || empty($message))
        exit('Error: You didnt fill all the field.);
     else {
           // split the address separate by ";"
       $addr = explode(";", $to);   // $addr now array
       // loop to send the email to all address
       foreach ($addr as $address) {
             // new code
             print "Sending mail to $address..."
             sleep(1);   // sleep execution for 1 second
         if (mail($address, $subject, $message, $from))
               print "done!<br />";
             else
               print "failed!<br />";

               flush();   // force the browser to print the output, even the HTML is incomplete
        }
            print "Finished processing ".count($addr)." address";
     }
  break;
}
?>


Does anyone have an idea to make some improvement? smile.gif

 

 

 


Reply

goldrain
wanna learn about mail form :



--------------------------------------------------------------------------------

Example 1

This is simple sendmail script (to easy, right???):

<?php
$txt = "First line of text\nSecond line of text";// Use wordwrap() if lines are longer than 70 characters
$txt = wordwrap($txt,70);// Send email
mail("somebody@example.com","My subject",$txt);
?>


--------------------------------------------------------------------------------

Example 2
U can send an email with extra headers:

<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";mail($to,$subject,$txt,$headers);
?>


--------------------------------------------------------------------------------

Example 3
U can send an HTML email like this example (note: you recuired MIME to send it)

<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email conatins HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";mail($to,$subject,$message,$headers);
?>

more info:
1. don't insert this mark "" in your $message or you will get an error
2. you can insert avvariable in your mail like this script:
--------------------------------------------------------------------------------
Example 4
HTML email that send users information


<html>
<body>
<form method=post action="">
<input type=text name=textfield>
<input type=submit name=button>

<?php
if (isset ($_POST["button"]))
{
$to = $_POST["textfield"] ;
$subject = "HTML email";$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email conatins HTML Tags!</p>" ;
$message.= "<p>your e-mail :".$_POST["textfield"] ;
$message.="
NICE TO MEET YOU!!!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";mail($to,$subject,$message,$headers);
echo "mail was sent" ;
}
else
{
echo "mail can't send" ;
}
?>
</body></html>


hope this useful for you!!!!

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. code in vb needed on how to load a form when clickd on a button - 339.12 hr back. (1)
Similar Topics

Keywords : email, form, simple

  1. A Question About Php Mail
    A question about how php send mail using which email account in SMTP s (1)
  2. An Interesting Approach To Email Verification...
    (6)
    I was thinking just now and I came up with a very interesting solution for email verification.
    It's actually based off of how alot of spammers get your email: Dynamic images. You could have
    a dynamic image display in the email that activates the account when loading it. The only downfall
    to it is if your users are using a an email provider such as Gmail, the images will be blocked, but
    I have a solution for that too. You could have the image say "Congratulations your account has been
    activated". And then below the image in plain text write "If you do not see the....
  3. Php Email Validation
    A PHP data validation class with many functions (1)
    I've been reading through my old php book (PHP 4.1) and came across this data validation class.
    It can check a number of things ranging from telephone numbers , credit card number formats, email
    address and some others. I checked out some of the methods although I didnt expect it to work 100%
    because I've found source code errors thoughout the book and CD. I tested out a few of the
    methods to check and some of them did return expected results but some didnt either so the data
    validation class was not perfect and it didnt really bother me. The cool thing I found....
  4. Trouble With Phpbb Email
    (1)
    Hi guys, I want to know if there is anything you can do for sending confirmation email to your
    users automatically when they have just regeistered, when the host server does not support SMTP
    (Simple Mail Transfer Protocol). ? Thanks alot.....
  5. Email Sending.
    email sending with php. (1)
    this script allow user to send an email for you. i hope you enjoy /wink.gif"
    style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> CODE
    [color="#0000ff"][indent]<?      $top='<html
    dir="rtl">      <head>   <meta http-equiv="Content-Language"
    content="fa">   <meta http-equiv="Content-Type" content="text/html;
    charset=utf-8">   </head>      <body>      <div
    align="center">       <p style="margin-top&....
  6. Add Users On Email Program With Php?
    (1)
    First of all Marry Christmas, Well so i am in some kind of a problem, i can't find out how to
    add users to my mail service, i have no idea what SMTP/IMAP program the server runs, neither does
    the system administrator. But it should be kinda the same thing for all of them if i am not wrong,
    Anyways i have full access to server so i can do whatever i want to do, i have SSH access too (Root
    access /rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0"
    alt="rolleyes.gif" /> )....
  7. Email Header Inject Test
    (0)
    So I'm trying to write a script to check if someone is trying to do a header inject using my web
    based email form. The problem is that, regardless of the content, it is being tagged as hijacked.
    The following is the relevant part of my code: CODE $ip=$_POST['ip'];
            $httpref=$_POST['httpref'];
            $httpagent=$_POST['httpagent'];
            $visitor=$_POST['visitor'];
            $visitormail=$_POST['visitormail'];         $s....
  8. Wappymail_v1.50
    wap free mail/ email admin script :-) (15)
    Here is my new wap mail script. You can use it as a free email sending service or an email admin
    form (can set this option in config.php) its extremly simple to install and you will find full
    instructions in the zip file. Please feel free to comment, rate, or update this script :-)
    /tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> ....
  9. Yet Another Problem With A Form Script
    Maybe I should just use email? lol (6)
    Okay, here is what I got. I know, three topics on form scripts, but hey, I am learning. I used a
    generator, and then put it on, but it is giving me a santax (is that how you spell it) on line 13
    with an unexpected = sign. I recited taht the best I could. Anyway, so I need some help. The form
    is located in http://inneed.mxweb.co.uk/askandanswer.html The script behind the whole works, I
    named, aaform.php. Moving right along here, I got this error, so here is the code that I called
    aaform.php, you know the one that works the whole thing: CODE <?php // Webs....
  10. Email Server Help Please
    I need noob detailed help on setting up a email server on windows XP (0)
    Hello I would like to say thank you for any help you might give me. I'm new to Apache / PHP and
    MySQL I have all them up and running propertly I think. I want to make a PHP online game and I need
    to set up an email server so I can have and authincation system. When the player creates an account
    I want the computer to email the player a link the have to click on to make there account active.
    I have a Comcast 8mbits broadband connection My server is running at http://192.168.1.105 My
    PHPinfo file is http://192.168.1.105/phpinfo.php My FormMail File http://192....
  11. Sending Attachments Using Email Function In Php
    (2)
    I'm trying to send an attachment using the mail Php function. It gets caught by the email
    server with an error. It seems to have a problem with the separator or who knows what. The server
    says something like "invalid separator on mime type." The code is: Code: CODE  // subject
    $subject  = "Hello There "; $mime_boundary =
    "<<<--==-->>>";        // headers        $headers  =
    "From: " . 'Tom' . " <" . 'texample@aol.com' .
    ">\r\n"; �....
  12. Protecting Web Email Forms
    (3)
    i have a web form on my site which can be filled in with a customers email, name and question or
    comment. when the form is submitted an email is sent to an address i setup with all the info.
    recently i've been getting alot of spam/junk coming from the web form. for the most part, they
    usually come pretty close together, which makes it seem like just one spammer (at least at a time).
    also i'm talking like 5-10 messages at a time. i'm wondering if people have any
    suggestions how to protect these types of web forms from spammers. any ideas/help is appreciate....
  13. Form To Pdf, With Email?
    Wanting to Submitt Data to PDF (3)
    Hi all, This sounds like a good place to ask this, I have a form Click Here to View that when
    submitted will put the values into the PDF Here Is there a way in which to have the filled in
    form both viewed to the user? and also have it emailed to me as an attachment. Any code or help
    would be good... I get basics, but this stuff is hard to get to work and i can't get it to.....
  14. Trouble With Emailer.php
    failed sending email error (6)
    Whenever someone registers at my forum, they get this error: Failed sending email :: PHP :: DEBUG
    MODE Line : 234 File : emailer.php however, the account will be sucessfully registered. It is
    weird because i did not change the original emailer.php at all. O__O||| anyone know whats up with
    it?....
  15. Email Code
    (3)
    CODE if($submit) //If submit is pressed { mail("youremailaddress@whatever.com",
    "$subject", "$email", "$comments"); } else {?> '> E-Mail: Subject:
    Comments: ....

    1. Looking for email, form, simple

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for email, form, simple

*MORE FROM TRAP17.COM*
advertisement



Email Form - Very Simple



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE