Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 06-21-2009, 06:52 PM   #1 (permalink)
Registered User
 
neonjuice's Avatar
 
Join Date: Dec 2008
Location: Minnesota
Posts: 113
OS: Vista Ultimate 64 bit SP1. Linux Ubuntu, XP Pro


PHP Email form problem

Ok. I am stuck and I feel damn stupid for this.

I am making an email send form, that will contain several sections. Users email addy, phone number, question and several other options.

I have developed this PHP form,but unsure exactly where to put my email address for it to send all the info to my inbox. I have been working 4am shifts this week and tired, I just can not see where I am going wrong. Still learning PHP. I do currently have the form in place using XHTML, but wish to program with PHP mainly from now on. Plus I got to learn all this inside out for college, when I start in September.

Here is my PHP code.

Code:
<?php

/*variable names for xhtml input*/
$name = $HTTP_POST_VARS ['name'];
$email = $HTTP_POST_VARS['email'];
$phone = $HTTP_POST-VARS['phone'];
$contact_choice = $HTTP_POST_VARS ['contact'];
$quick_form = $HTTP_POST_VARS ['quickform'];
$time = $HTTP_POST_VARS ['time'];
$message = $HTTP_POST_VARS['message'];

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email='example@example.com')) **
  echo "<h4>Invalid email address</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($message == "") **
  echo "<h4>You have not entered a message </h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}


elseif (mail($name,$email,$phone,$contact_choice,$quick_form,$time,$message )) **
  echo "<h4>Thank you for contacting us, you shall receive a reply very soon.</h4>";
} else **
  echo "<h4>Can't send email to $email</h4>";
}
?>
Here is my XHTML side of the code, just included the Form part of the code.

Code:
<$php
<form action="mail.php" method="POST">
<strong>Name:</strong>     <input type="text" size="10" maxlength="40" name="name" /> <br />
<br />
 <strong>Email: </strong>  <input type="text" size="10" maxlength="45" name="email" /><br />
 <br />
 <strong>Phone:</strong> <input type="text" size="10" maxlength="45" name="phone" /><br />

 <br />
 <br />
 <center><cite><u><strong>How would you like us to contact you?</strong></u></cite></center>
 <br />
 <input type="checkbox" name="email" value="email" /> Email
 <input type="checkbox" name="phone" value="phone" /> Phone
 <br />
 <br />

 <center><cite><u><strong>Select an option to help process your email quicker</strong></u></cite></center>
 <br />
    <input type="checkbox" name="quickform" value="t-shirts" />T-shirts
          <input type="checkbox" name="quickform" value="shorts" />Shorts
          <input type="checkbox" name="quickform" value="tank tops" />Tank tops
          <input type="checkbox" name="quickform" value="General Query" />General Query
          <br />
          <br />
          Best time to contact you? :
<select name="time" />
<option>Select Time</option>

<option>9am - 12 noon</option>
<option>Noon - 6pm</option>
<option>6pm - 9pm</option>
</select>
<br />
<br />
<textarea rows="10" cols="80" wrap="physical" name="message" />
Enter text here:
</textarea>
<br />
<br />
<input type="submit" value="Send" />
</form>
I think I may have gotten my self confused and would love some help from you guys.
It is near bed time,. back up at 3am for work. The 3 days off, to get this sorted and get lots of other work completed.
neonjuice is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 06-22-2009, 08:55 AM   #2 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 698
OS: Ubuntu Linux

My System

Re: PHP Email form problem

You can probably simplify the email address validation with PHP5's filter_var:

PHP Code:
filter_var('bob@example.com'FILTER_VALIDATE_EMAIL
I don't have time to test this morning, but I'll spit out a little code for you to check...if it doesn't work, I'll go over it more...

PHP Code:
<?php

/*variable names for xhtml input*/
$name $_POST['name'];
$email $_POST['email'];
$phone $_POST['phone'];
$contact_choice $_POST['contact'];
$quick_form $_POST['quickform'];
$time $_POST['time'];
$message $_POST['message'];

$email filter_var($emailFILTER_VALIDATE_EMAIL);

if(
$email==false)
    **
    echo 
"<h4>Invalid email address</h4>";
    echo 
"<a href='javascript:history.back(1);'>Back</a>";
    }    elseif(
strlen($message)==0)    **
    echo 
"<h4>You have not entered a message </h4>";
    echo 
"<a href='javascript:history.back(1);'>Back</a>";
    }    

// now that we've made it through error checking, put together the mail properties
$mailmessage 'Name: ' $name "\n";
$mailmessage .= 'Email: ' $email "\n";
$mailmessage .= 'Phone: ' $phone "\n";
$mailmessage .= 'Contact?: ' $contact_choice "\n";
$mailmessage .= 'Time: ' $time "\n";
$mailmessage .= "\n";
$mailmessage .= 'Message: ' "\n";
$mailmessage .= $message;

$subject 'New mail';

$headers 'MIME-Version: 1.0' "\r\n";
$headers .= 'From: ' $name '<' $email '>' "\r\n";

if(@
mail('you@youremail.com'$subject$mailmessage$headers))
    **
    
// the '@' will suppress errors
    
echo "<h4>Thank you for contacting us, you shall receive a reply very soon.</h4>";
    }    else    **
    echo 
"<h4>Can't send email to $email</h4>";
    }
?>
Take notice:
  • I've changed $HTTP_POST_VARS to $_POST. Some people have reported problems when using that - and $_POST always works.
  • I've implemented the filter_var function I described above. This function can do more than validating emails, if you're ever interested in other types of validations and sanitizing features it has.
  • You put together the mail function incorrectly. I put in a way that should play better with it. Remember, PHP.net's manual is your friend! Always refer to it for the proper way of setting up functions.
  • I haven't put in any functionality to prevent form hijacking/injections. I try to keep this stuff out of the scripts I sort out for people because it only confuses them (simpler is better) - although I've received email in the past criticizing that I haven't made a bigger deal out of such things, so I wanted to just mention that you'll need to put some code to keep your code/server safe. There is stuff around the Internet concerning this very thing - but I'll make a new post in this forum with a favorite article of mine (hint: that filter_var function comes in handy yet again!) and a little piece of code I use on everything.
  • Remember when copying this code to test it...this forum changes the opening bracket for the if statements to "**" - correct that before you run it, or it won't work.
__________________
Free Resources
PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |
Web Design/Programming - KompoZer
(Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting |
Redcore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-22-2009, 09:05 AM   #3 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 698
OS: Ubuntu Linux

My System

Re: PHP Email form problem

Oh by the way...
Quote:
Originally Posted by neonjuice View Post
Ok. I am stuck and I feel damn stupid for this.
There's no such thing as feeling stupid for asking for help when you're stuck! :) TRUST me, even if you're a pro you WILL make mistakes. There will be times where your code looks perfect as you've combed over it 10-15 times and it is just not working. Here's the key: you've messed it up. 99% of the time whenever something isn't working and I'm stuck, it really is just me. There have been times where I've sat there staring at code for 2+ hours and am so frustrated I'm throwing things around the office - so I decide to go home or work on something else and come back to it the next day with a fresh perspective...only to find that it was indeed just me and I made a mistake that, for whatever reason, I was unable to find (typically it's a very small mistake!). There will be times where you'll make a mistake and go "DOH! I knew better than that!"

So long as you've tried to figure it out yourself and come to us with some code in hand, myself and others will always be happy to help. I just don't like to spend any time helping those who want us to do their work for them or teach them how to do things - but I go out of my way to teach those who show effort and want to learn...
__________________
Free Resources
PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |
Web Design/Programming - KompoZer
(Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting |
Redcore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


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 Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 02:33 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85