x10Hosting Forums

Corporate Free Hosting for the Masses.



Register

Reply
 
LinkBack Thread Tools Display Modes
x10Hosting Member

goldy30's Avatar

Join Date: Jul 2008
Posts: 49
Credits: 888
goldy30 is on a distinguished road
Quote  
09-30-2008, 11:28 AM
TAFE STUDENT - PHP - Send mail - Verify feilds

It's not something we've done yet, although we have done a bit of php. I put a basic sendmail.php but it doesnt stop users slapping the submit button which sends me a blank email.

I tried something like this but its giving me errors about '{' and other stuff.. I've changed it a few times but I'm not fully versed on php.

Any thoughts?

<?php
$first_name=$_REQUEST['first_name'];
$last_name=$_REQUEST['last_name'];
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

if (!isset($_REQUEST['email'])) {
header( "Location: http://www.housepainter.pcriot.com/contact.htm" ); // header is obviously a problem, yes??
}
elseif (empty($email) || empty($message)) {
header( "Location: http://www.example.com/contact_error.htm" ); //how do you redirect to a page?
}
else {
mail( "myname@example.com", "Contact Notification",
$message, "From: $email" );
}
?>
www.housepainter.pcriot.com

Thanks,
TAFE STUDENT
Edit:
it's obviously wrong but Im not sure?? I get this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/goldy30/public_html/sendmail.php:8) in /home/goldy30/public_html/sendmail.php on line 29

Last edited by goldy30; 09-30-2008 at 11:34 AM. Reason: Automerged Doublepost
Reply With Quote
goldy30 is offlineReport Post
x10 Sophmore

xmakina's Avatar

Join Date: May 2008
Posts: 239
Credits: 2,077
xmakina will become famous soon enough
Location: England

Send a message via MSN to xmakina
Quote  
09-30-2008, 11:42 AM
Re: TAFE STUDENT - PHP - Send mail - Verify feilds

Go read up on PHP over a www.w3schools.com.

Also, I use <meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"> to redirect folks to pages.
Reply With Quote
xmakina is offlineReport Post
x10Hosting Member

Join Date: Aug 2008
Posts: 25
Credits: 488
Nahid_hossain is on a distinguished road
Location: Dhaka, Bangladesh

Quote  
10-01-2008, 01:05 AM
Re: TAFE STUDENT - PHP - Send mail - Verify feilds

Is this your full script? Because header("Location: $url") never gives this kind of error if no html tag or contents generates b4 the header.

This means your script generates html contents before sending this header.

I've also tried this piece of code myself and it is working fine on my server.
Reply With Quote
Nahid_hossain is offlineReport Post
x10 Sophmore

Join Date: Sep 2007
Posts: 229
Credits: 33,068
scorch94 is on a distinguished road
Quote  
10-01-2008, 01:44 AM
Re: TAFE STUDENT - PHP - Send mail - Verify feilds

I guess header() is a problem.
Try this:
header("Location: blabla"); die();
I guess that should do it.
__________________

Reply With Quote
scorch94 is offlineReport Post
x10 Lieutenant

freecrm's Avatar

Join Date: May 2008
Posts: 272
Credits: 956
freecrm will become famous soon enough
Location: UK

Quote  
10-02-2008, 04:54 PM
Re: TAFE STUDENT - PHP - Send mail - Verify feilds

This doesn't really control data entry very well.

I use javascript to check each form field. You can then validate field formats, nulls, comparisons etc etc. and even colour the fields when they are wrong/ correct...

I don't think this level of control is possible in php.

This is all provided the user permits JS!
__________________
Rich

If you liked this post, please give me +rep or donate credits.

My Site:

Last edited by freecrm; 10-02-2008 at 04:55 PM.
Reply With Quote
freecrm is offlineReport Post
x10 Lieutenant

Join Date: Oct 2007
Posts: 438
Credits: 4,200
mattura is just really nice
Quote  
10-02-2008, 06:21 PM
Re: TAFE STUDENT - PHP - Send mail - Verify feilds

Use javascript in the first instance, but also use the PHP to check, along the lines of:
PHP Code:
$message=$_REQUEST['message'] ;
$err=false//no error, yet
if ($message=="") {$err=true;} //blank message will create error
...
if (!
$err) { //if no error
 //send the email
 
...
} else {
 
//an error, dont send the email
 
echo "Please fill in all fields!";

Obviously you can check other fields too, and clean the input to be safe, check for a valid email address etc.
But the above will stop a blank message from being sent.
To find an email validating expression, look up preg_match in php docs
__________________
----
Please donate credits if you had a really good reply from me! Rep is also appreciated. Thanks
matt.elementfx.com
Reply With Quote
mattura is offlineReport Post
x10 Lieutenant

freecrm's Avatar

Join Date: May 2008
Posts: 272
Credits: 956
freecrm will become famous soon enough
Location: UK

Quote  
10-03-2008, 08:04 AM
Re: TAFE STUDENT - PHP - Send mail - Verify feilds

Quote:
Originally Posted by mattura View Post
To find an email validating expression, look up preg_match in php docs
Ooooh... didn't know about this!
__________________
Rich

If you liked this post, please give me +rep or donate credits.

My Site:
Reply With Quote
freecrm is offlineReport Post
x10 Lieutenant

Join Date: Oct 2007
Posts: 438
Credits: 4,200
mattura is just really nice
Quote  
10-04-2008, 05:27 PM
Re: TAFE STUDENT - PHP - Send mail - Verify feilds

Hehe, your first dive into regular expressions? They are mighty confusing, I find myself having to re-learn something every time I want to use them!

I'd recommend preg_match and preg_replace over things like eregi. They tend to be more efficient and don't tend to have various security holes.

Everyone has their own idea about what a valid email should be, but here's a simple one:
PHP Code:
$validemail="/^[a-z0-9._-]+@[a-z0-9_-]+\.[a-z0-9._-]+$/i";
if (
preg_match($validemail,$_POST['email'])) {
 
//email is valid

That is to say:
at least one number/letter/dot/underscore/hyphen, followed by the @ sign, followed by at least one number/letter/underscore/hyphen, followed by a dot, followed by at least one number/letter/underscore/hyphen/dot

So it's not perfect as "-@-.-" (for example) is valid, but you can never check everything...at least it's not too restrictive, so all valid emails should work.
__________________
----
Please donate credits if you had a really good reply from me! Rep is also appreciated. Thanks
matt.elementfx.com
Reply With Quote
mattura is offlineReport Post
Reply

Tags
php

Thread Tools
Display Modes

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
[?] how to send mail in php? bo17age Programming Help 5 09-11-2008 05:21 AM
Send mail with PHP messa Free Hosting 2 09-11-2008 05:12 AM
currently have an application pending php biomasti Free Hosting 1 09-03-2008 02:58 PM
Unstand PHP? o0slowpaul0o Tutorials 8 01-07-2008 10:16 PM


All times are GMT -5. The time now is 06:13 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC7
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

Fast Loans | GBA Roms | Car Credit | Problem Mortgage | Takeaway insurance