www.webdeveloper.com
Results 1 to 9 of 9

Thread: PHP not working...please, help.

  1. #1
    Join Date
    Aug 2010
    Posts
    32

    Email PHP not working...please, help.

    Hi, everyone. Ok, so I've got this email PHP code and I've loaded it on my site, but it doesn't do anything. When I press submit it just goes to the PHP page. It just shows the code instead of performing it. Here is the code:

    Code:
    <?php
    
    $EmailTo = "lonogod@yahoo.com, lonogod1@yahoo.com";
    $Subject = "Birthday Dinner Request";
    $Name = Trim(stripslashes($_POST['Name'])); 
    $Entree = Trim(stripslashes($_POST['Entree'])); 
    $Side1 = Trim(stripslashes($_POST['Side1'])); 
    $Side2 = Trim(stripslashes($_POST['Side2'])); 
    $Dessert = Trim(stripslashes($_POST['Dessert'])); 
    $AddInfo = Trim(stripslashes($_POST['AddInfo'])); 
    
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Entree: ";
    $Body .= $Entree;
    $Body .= "\n";
    $Body .= "Side1: ";
    $Body .= $Side1;
    $Body .= "\n";
    $Body .= "Side2: ";
    $Body .= $Side2;
    $Body .= "\n";
    $Body .= "Dessert: ";
    $Body .= $Dessert;
    $Body .= "\n";
    $Body .= "AddInfo: ";
    $Body .= $AddInfo;
    $Body .= "\n";
    
    $success = mail($EmailTo, $Subject, $Body, "From: <$Name>");
    
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=requests-true.html\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=requests-false.html\">";
    }
    ?>
    What could be the problem? Thanks in advance!

    - Lono
    Last edited by lonoman; 08-09-2010 at 07:34 PM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,359
    (a) Does your web hosting account support PHP?

    (b) Did you give the file a ".php" file name suffix?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2010
    Posts
    32
    I was just about to post back here. I got off the phone with my web host and they don't allow server-side scripts. I think that's ridiculous, but whatever. Is there any other way to send an email from an online form without using mailto? Thanks for the help.

    - Lono

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,359
    Not without some sort of server-side scripting. Whether it be PHP, ASP, JSP, C#, or whatever, it requires some sort of programming on the server side.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Aug 2010
    Posts
    32
    Well, that sucks. I guess I'll have to look into something else. Thanks!

    - Lono

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,359
    Or look into moving to another host (or seeing if the current one has an upgrade package with what you need).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Aug 2010
    Posts
    32

    script works in FF but not IE...?

    I moved the site to a different host, but now it only works in FF and does not work in IE. It sends an error email instead of the form information. Here is the updated code:
    Code:
    <?php
    
    $EmailTo = "emial1@yahoo.com, email2@yahoo.com";
    $Subject = "Birthday Dinner Request";
    $Name = Trim(stripslashes($_POST['Name'])); 
    $Entree = Trim(stripslashes($_POST['Entree'])); 
    $Side1 = Trim(stripslashes($_POST['Side1'])); 
    $Side2 = Trim(stripslashes($_POST['Side2'])); 
    $Dessert = Trim(stripslashes($_POST['Dessert'])); 
    $AddInfo = Trim(stripslashes($_POST['AddInfo'])); 
    
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Entree: ";
    $Body .= $Entree;
    $Body .= "\n";
    $Body .= "Side1: ";
    $Body .= $Side1;
    $Body .= "\n";
    $Body .= "Side2: ";
    $Body .= $Side2;
    $Body .= "\n";
    $Body .= "Dessert: ";
    $Body .= $Dessert;
    $Body .= "\n";
    $Body .= "AddInfo: ";
    $Body .= $AddInfo;
    $Body .= "\n";
    
    $success = mail($EmailTo, $Subject, $Body, "From: $Name");
    
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=http://blahblahblah.com/requests-true.html\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=http://blahblahblah.com/requests-false.html\">";
    }
    ?>
    Any idea why it wouldn't work in both? Thanks!

    - Lono

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,359
    It shouldn't matter which browser, but I might be concerned with the "From: $Name", as many mail hosts require that the "From:" email header be a valid, existing email address on that host. If you want to use the user's email address, you may want to put it in a "Reply-To:" header instead, and use a hard-coded email address for the From that you know is valid, e.g.:

    PHP Code:
    $reply trim($_POST['email']); // or whatever $_POST element it is
    $header "From: somebody@yoursite.com\r\nReply-To: $reply";
    $success mail($EmailTo$Subject$Body$header); 
    If that's not the issue, it could be an issue with the HTML used for the form that is submitting to this script.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Aug 2010
    Posts
    32
    I just created the $EmailFrom variable with a valid email address. That fixed it. Thanks, NogDog!

    - Lono

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles