Secure E-mail form troubles

This is a discussion on "Secure E-mail form troubles" within the PHP Forum section. This forum, and the thread "Secure E-mail form troubles are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 13th, 2007, 23:22
BGarner's Avatar
Reputable Member
Join Date: Oct 2006
Location: In front of the computer.
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Secure E-mail form troubles

So I finally gave in and started learning php. I breezed through the beginner tutorial at w3schools, but the I hit my first glitch in the advanced tutorial.

I tried using their Email scripts but I can't seem to get it to send an email to myself. The script can be found here http://www.thehtmldude.com/test.php

The code is...
Code: Select all
<?php
function spamcheck($field)
  {
//eregi() performs a case insensitive regular expression match
  if(eregi("to:",$field) || eregi("cc:",$field)) 
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }

//if "email" is filled out, send email
if (isset($_REQUEST['email']))
  {
  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==TRUE)
    {
    echo "Invalid input";
    }
  else
    { 
    //send email
    $email = $_REQUEST['email'] ; 
    $subject = $_REQUEST['subject'] ;
    $message = $_REQUEST['message'] ;
    mail("bgarner.webdesign@gmail.com", "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='/test.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>";
  }
?>
I think the problem is in
Code: Select all
<form method='post' action='/test.php'>
Thanks!
Reply With Quote

  #2 (permalink)  
Old Mar 14th, 2007, 12:09
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Secure E-mail form troubles

I'm barely adequate with mail() myself, but I'll try to help. The #1 area I can't talk about is server configuration, which could be your problem. Check your php.ini settings for mail.
Code: Select all
<?php
function spamcheck($field)
  {
//eregi() performs a case insensitive regular expression match
  if(eregi("to:",$field) || eregi("cc:",$field)) 
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }
I'd take out this function, first off. I realize you might want to use the function-making device for practice, but this just feels odd to me, and is certainly unnecessary. I use Perl for regex, but iirc ereg() returns string length when successful and NULL when not, so you don't need to a function to create a return.

Code: Select all
//if "email" is filled out, send email
if (isset($_REQUEST['email']))
  {
  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==TRUE)
    {
    echo "Invalid input";
    }
  else
I'm not following you here. If you want to check the validity of the email address -- an excellent idea -- you need slightly complicated regex. The net has a lot of good examples. Maybe your comment ('check if the email address is valid') just threw me off, and all you're trying to do is trigger an initial email by seeing if the form has been filled out.

I don't see a problem with "<form method='post' action='/test.php'>". However, I would suggest that you add value="submitted" to the submit input and use this format:
Code: Select all
if ((isset($_POST['submit'])) && ($_POST['submit']=='submitted'))  {
- send email -
} else {
- echo the form - 
}
This is my boilerplate for a one page form/handler. BTW, you will get a slightly faster response, in general, by using the XML format './test.php' for relative urls.

I don't know why you use $_REQUEST instead of $_POST here, since you don't have any cookie or GET content in the email. I don't like allowing GET variables into my form-handling unless absolutely necessary. It should work, though. You see it done a lot in email forms, so there may be something I don't know understand.

I know this is disjointed. I hope it's some help, at least.
Reply With Quote
  #3 (permalink)  
Old Mar 15th, 2007, 20:22
BGarner's Avatar
Reputable Member
Join Date: Oct 2006
Location: In front of the computer.
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Secure E-mail form troubles

Thanks,

Like I said, I mostly just tweaked the script at w3schools. I may just need to write my own and look at server settings.
Reply With Quote
Reply

Tags
php email, secure email

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Making the form Secure & Restricting Chars PicoDeath PHP Forum 3 Aug 2nd, 2007 20:00
PHP form and server troubles nglenister PHP Forum 3 May 1st, 2007 12:21
Can someone help me with this e-mail form??? johnson8707 JavaScript Forum 9 Jul 5th, 2006 22:23
visitors name not displayed in mail after filling in mail form made on earth PHP Forum 7 Nov 16th, 2005 22:43
E-mail form ??????? pittypatter Web Page Design 3 Apr 11th, 2005 23:42


All times are GMT. The time now is 06:46.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43