Find the answer to your Linux question:
Results 1 to 6 of 6
hi guys, this is my code at the moment PHP Code: <?php if (isset( $_REQUEST [ 'email' ])) &&  $_REQUEST [ 'email' ]!= '0' {      $to  =  "chrisathisemail" ;      $subject  ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    11

    Basic PHP Mail function help


    hi guys, this is my code at the moment

    PHP Code:
    <?php
    if (isset($_REQUEST['email'])) && $_REQUEST['email']!='0'{
        
    $to "chrisathisemail";
        
    $subject "Contact Form Enquiry";
        
    $message $_REQUEST["message"];
        
    $from $_REQUEST["email"];
        
    mail($to,$subject,$message,$from);
        
    header('Location: thanks.php');}
    else{
    header('Location: error.php');}
    exit();
    ?>

    ?>
    this bit of the code
    PHP Code:
    && $_REQUEST['email']!='0' 
    Its the bitjust above is what I am getting wrong, what is the correct way to say 'and if 'email' is not equal to 0 then send the mail.

    Thanks, hope you understand what im trying to do.

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Not that I know PHP, but it could be a problem with the parentheses. Try making the second ')' to embrace the second condition as well.
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined!
    Join Date
    Nov 2009
    Posts
    11
    Thanks, I got it working now.

    Now I have another issue with the same script. If I host the site locally through apache (127.0.0.1) the script executes but the email does not send, however it does redirect to the specified pages properly like it should.

    However if I hose the exact same site on my proper server the script does not execute, when I click on the submit button a dialogue box pops up asking if i want to open or download the script. Any ideas why that is happening?

    PHP is installed on the server as the site is created using php "includes" and they work fine, just not this annoying script!

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Quote Originally Posted by Chris1989 View Post
    However if I hose the exact same site on my proper server the script does not execute, when I click on the submit button a dialogue box pops up asking if i want to open or download the script. Any ideas why that is happening?
    Your webserver is not configured properly. You must configure it so that it passes .php files to the PHP interpreter instead of delivering them to the webbrowser that asked for it.
    Debian GNU/Linux -- You know you want it.

  6. #5
    Just Joined!
    Join Date
    Nov 2009
    Posts
    11
    Ok thanks, do you know how I do that?

    Actually, its not that as I have another site on the same server that processes a similar contact script fine..

  7. #6
    Linux User
    Join Date
    Dec 2009
    Posts
    264
    First make sure the script has the right extension ...
    most used for php files: .php
    second make sure your web-server has the rights to execute it ...
    you can take a look at that with ls -al
    if there's no execution right it won't work.
    chmod 755 file.php
    will set it as executable.

    I don't know any other reason why the web-server won't execute the php scripts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •