+ Reply to Thread
Results 1 to 8 of 8

Thread: TAFE STUDENT - PHP - Send mail - Verify feilds

  1. #1
    goldy30's Avatar
    goldy30 is offline x10Hosting Member goldy30 is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    60

    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: in /home/goldy30/public_html/sendmail.php on line 29
    Last edited by goldy30; 09-30-2008 at 10:34 AM. Reason: Automerged Doublepost

  2. #2
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    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.

  3. #3
    Nahid_hossain is offline x10Hosting Member Nahid_hossain is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Dhaka, Bangladesh
    Posts
    28

    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.

  4. #4
    scorch94 is offline x10 Sophmore scorch94 is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    228

    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.

  5. #5
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    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!
    Last edited by freecrm; 10-02-2008 at 03:55 PM.

  6. #6
    mattura's Avatar
    mattura is offline x10 Elder mattura is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    563

    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
    ----
    Life is a game. The conception is terrible but the graphics are amazing!
    matt.elementfx.com

  7. #7
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    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!

  8. #8
    mattura's Avatar
    mattura is offline x10 Elder mattura is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    563

    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.
    ----
    Life is a game. The conception is terrible but the graphics are amazing!
    matt.elementfx.com

+ Reply to Thread

Similar Threads

  1. [?] how to send mail in php?
    By bo17age in forum Programming Help
    Replies: 5
    Last Post: 09-11-2008, 04:21 AM
  2. Send mail with PHP
    By messa in forum Free Hosting
    Replies: 2
    Last Post: 09-11-2008, 04:12 AM
  3. currently have an application pending php
    By biomasti in forum Free Hosting
    Replies: 1
    Last Post: 09-03-2008, 01:58 PM
  4. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers