404 error when POSTing to custom php

Discussion in 'Customization & add-ons' started by primitive_soul, Feb 25, 2013.

  1. primitive_soul

    primitive_soul New Member

    Joined:
    Oct 11, 2010
    Messages:
    14
    Hi, I own a tattoo studio and I've created a custom page in the members info area (I'm using 4.2.14). The page is a "artists profile" page for my artists with each of their info and links loading from an XML file. I'm trying to provide a text area where members can send an email to my artists personal emails without ever seeing their addresses. Right now I have a form set up like this:
    PHP:
    <form action="sendmessage.php" method="post">
              <input type="hidden" name="address" value="<?php echo $art->eml ?>">
              <textarea name="message" rows="4" cols="60" placeholder="Send <?php echo $art->name ?> a message!" required></textarea><br>
              <input type="submit" name="submit" value="Send" height="30px">
              </form>
    And a custom "sendmessage.php" in the "members" folder that is in the root folder. It looks like this:
    PHP:
    <?php
    if (isset($_POST['submit'])) {
    echo 
    "your message was sent";
    }
    ?>
    The form action seems to work but it can't seem to find that file. This will contain my email function. I get a 404 error every time. Maybe I'm not putting it in the right place? I would like the file protected inside the members folder. Of course I'm not set on necessarily doing it this way. Can I post to a script already built into amember?
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Do you have amember installed in that folder as well?
    If so try to modify .htaccess file inside your members folder and add this line:
    RewriteRule ^public public.php [L]
    RewriteRule ^js.php js.php [L]
    RewriteRule ^sendmessage.php sendmessage.php [L]
  3. primitive_soul

    primitive_soul New Member

    Joined:
    Oct 11, 2010
    Messages:
    14
    yes, my members folder is the amember folder renamed during the setup process. I had a feeling my problem had to do with security access. I will try it right away. Thank you.
  4. primitive_soul

    primitive_soul New Member

    Joined:
    Oct 11, 2010
    Messages:
    14
    I tried adding it with the other un-commented lines in the htaccess file in my members folder with no effect. then I modified my path in my form to be more specific (../members/sendmessage.php) and that didn't help either. Getting past this little hurdle is very important to me because the same principles will apply to other sections I have planned for the site.
  5. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Well, the simplest solution will be to move that file outside of aMember's installation folder.
    For example place to to /private/sendmessage.php
  6. primitive_soul

    primitive_soul New Member

    Joined:
    Oct 11, 2010
    Messages:
    14
    Well, that did work. I wonder if amember will interfere if I use it to set up protection for that folder? I'll try it and post the results in case anyone else out there is wondering.
  7. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    No. This is ok to set protection for that folder.
  8. primitive_soul

    primitive_soul New Member

    Joined:
    Oct 11, 2010
    Messages:
    14
    Ok. I haven't set protection for that folder yet and I built the function to parse the post and send the email as per the DI/API page in the documentation. It gets through all of it and then has an mail send error (the one located on line 21). Here's the code:
    PHP:
    <?php
    include '../members/bootstrap.php';
    if (isset(
    $_POST["submit"])) {
    $Artmail $_POST["eml"];
    $Uname $_POST["uname"];
    $Rname $_POST["realname"];
    $Umail $_POST["umail"];
    $message $_POST["message"];
     
    $messagefinal $Uname."\n".$Rname."\n".$Umail."\n".$message;
    $messagefinal wordwrap($message70"\r\n");
    $subject "Tattoo inquiry from ".$Rname;
     
    $mail Am_Di::getInstance()->mail// create copy of Zend_Mail object, preconfigured by aMember
    $mail->addTo($Artmail);
    $mail->setSubject($subject);
    $mail->setBodyText($message);
    try {
      
    $mail->send();
    } catch (
    Exception $e) {
      echo 
    "Error sending e-mail: " $e->getMessage() . "\n";
    }
     
    echo 
    "your message was sent ".$Uname;
    echo 
    $messagefinal;
    }
    ?>
  9. primitive_soul

    primitive_soul New Member

    Joined:
    Oct 11, 2010
    Messages:
    14
    The error I get is:"Error sending e-mail: Unable to send mail."
  10. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    1. Check aMember CP -> Setup -> Email -> Mail sending method and make sure that it is correct. Try to send test email from that page.

    2. make sure that $Artmail = $_POST["eml"]; have valid email address, try to print that variable in order to see it value.

Share This Page