Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    My First PHP FORM(PROBLEM)

    PHP Code:
    #!/usr/bin/perl
    # location of Perl (above) - check your doc or ask admin

    ##### SETTABLE VARIABLES ####################################

    # URL to go to if there is a problem with form input
    $ErrorPage "http://www.yoursite.com/a_fail.html";

    # URL to go to when form has been successfully submitted
    $ThankPage "http://www.yoursite.com/a_thanks.html";

    # URL to go to if a 'foreign' referer calls the script
    $EvilReferer "http://www.somesite.com";

    # E-mail address to send intake form to (your address)
    # If not using PERL 5, escape the @ thus: \@ instead of @ 
    $YourEmail 'theYoungSociety@gmail.com';

    # Script works only on your server(s) - ('theyoungsociety.000hosted.com','www.theyoungsociety.000hosted.com')
    @referers = ('theyoungsociety.000hosted.com','www.theyoungsociety.000hosted.com');

    # Location of mail program - check your doc or ask admin
    $MailProgram '/usr/lib/sendmail';

    # Subject of the e-mail autoreply to the submitter
    $Subject "Thanks for Your Message!";

    # Header line in the auto-reply message
    $Header "GOOBERS UNLIMITED";

    # Brief tail message for body of e-mail autoreply
    $TailMessage "If your message requires a reply, we'll get back to you soon.";

    # Your signature lines the end of the autoreply e-mail
    $Signature1 "John Q. Public";
    $Signature2 "www.YourSite.com";

    ##### END OF SETTABLE VARIABLES ############################



    ##### MAIN PROGRAM #########################################
    # ___ Do not edit below this line __________________________

    &CheckReferingURL;
    &
    ReadParse;
    $Name $in{'Name'};
    $Email $in{'Email'};
    $Message $in{'Message'};
    &
    CheckEmailAddressFormat;
    &
    CheckFields;
    &
    GetDate;
    &
    SendSubmission;
    &
    SendAutoReply;
    print 
    "Location: $ThankPage\n\n";
    exit;

    # _________________________________________________________

    sub SendSubmission {
    open (MAIL,"|$MailProgram -t");
    print 
    MAIL "To: $YourEmail\n";
    print 
    MAIL "From: $Email\n";
    print 
    MAIL "Subject: $Subject\n";
    print 
    MAIL "$Date\n\n";
    print 
    MAIL "E-Mail Message\n\n";
    print 
    MAIL "From: $Name\n";
    print 
    MAIL "Email: $Email\n\n";
    print 
    MAIL "Message:\n\n";
    print 
    MAIL "$Message\n\n";
    close (MAIL);
    }

    # _________________________________________________________

    sub SendAutoReply {
    open (MAIL,"|$MailProgram -t");
    print 
    MAIL "To: $Email\n";
    print 
    MAIL "From: $YourEmail\n";
    print 
    MAIL "Subject: $Subject\n";
    print 
    MAIL "$Header\n";
    print 
    MAIL "$Date\n\n";
    print 
    MAIL "$Subject\n\n";
    print 
    MAIL "You sent the following:\n\n";
    print 
    MAIL "==============================\n\n";
    print 
    MAIL "Name: $Name\n";
    print 
    MAIL "Email: $Email\n\n";
    print 
    MAIL "Message:\n\n";
    print 
    MAIL "$Message\n\n";
    print 
    MAIL "==============================\n\n";
    print 
    MAIL "$TailMessage\n\n";
    print 
    MAIL "Best regards,\n\n\n";
    print 
    MAIL "$Signature1\n";
    print 
    MAIL "$Signature2\n\n";
    close (MAIL);
    }

    # _________________________________________________________

    sub GetDate {
    @
    days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
    @
    months = ('01','02','03','04','05','06','07','08','09','10','11','12');
    (
    $sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    $year $year+1900;
    $Date "$days[$wday] $months[$mon]/$mday/$year";
    }

    # _________________________________________________________

    sub ReadParse local (*in) = @if @_
    local ($i$key$val); if ( $ENV{'REQUEST_METHOD'eq "GET" 
    {
    $in $ENV{'QUERY_STRING'};} 
    elsif ($ENV{'REQUEST_METHOD'eq "POST"
    {
    read(STDIN,$in,$ENV{'CONTENT_LENGTH'});} 
    else { 
    $in = ( grep( !/^-/, @ARGV )) [0];
    $in =~ s/&/&/g; } @in split(/&/,$in);
    foreach 
    $i (.. $#in) { 
    $in[$i] =~ s/+/ /g
    (
    $key$val) = split(/=/,$in[$i],2); 
    $key =~ s/%(..)/pack("c",hex($1))/ge
    $val =~ s/%(..)/pack("c",hex($1))/ge
    $in{$key} .= "\0" if (defined($in{$key})); 
    $in{$key} .= $val; } return length($in); }

    # _________________________________________________________

    sub CheckEmailAddressFormat {
    if (
    index($Email"@") < 1)  {&DoEmailError;}
    if (
    index($Email".") < 1)  {&DoEmailError;}
    if (
    index($Email" ") > -1) {&DoEmailError;}
    }
    sub CheckFields {
    if (!
    $Name || $Name eq ' ') {&DoEmailError;}
    if (!
    $Email || $Email eq ' ') {&DoEmailError;}
    if (!
    $Message || $Message eq ' ') {&DoEmailError;}
    }
    sub DoEmailError {
    print 
    "Location: $ErrorPage\n\n";
    exit;
    }

    # _________________________________________________________

    sub CheckReferingURL {
    if (
    $ENV{'HTTP_REFERER'}) {
    foreach 
    $referer (@referers) {
    if (
    $ENV{'HTTP_REFERER'} =~ /$referer/i) {
    $check_referer '1';
    last;
    }}}
    else {
    $check_referer '1';}
    if (
    $check_referer != 1) {
    print 
    "Location: $EvilReferer\n\n";
    exit;
    }}

    # _________________________________________________________

    exit;

    ##### End of Script ######################################## 
    This Is The HTML Part of It:
    PHP Code:
    <html>
    <
    head>
    <
    title>Send us an e-mail...</title>
    </
    head>

    <
    body>
    <
    font size="5">Send us an e-mail...</font><font size="4"><br></font>
    <
    form action="/AlphaMail.pl" method="POST">
      <
    p><font size="4">Your Name (required):</font><br>
      <
    input type="text" name="Name" size="50"></p>
      <
    p><font size="4">Your E-mail (required):</font><br>
      <
    input type="text" name="Email" size="50"></p>
      <
    p><font size="4">Your message (required):</font><br>
      <
    textarea rows="6" name="Message" cols="45"></textarea></p>
      <
    p><input type="submit" value="Send" name="B1"> <input type="reset" value="Clear" name="B2"></p>
    </
    form>
    </
    body>
    </
    html
    PROBLEM: Every time i press the send button it shows me my php code. And I do not receive anything to my email.

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    What you have posted is not php - it's Perl. They are two different languages.

  • #3
    Regular Coder FWDrew's Avatar
    Join Date
    Apr 2008
    Location
    Missouri
    Posts
    380
    Thanks
    38
    Thanked 45 Times in 43 Posts
    Would this:
    PHP Code:
    #in) { 
    Have anything to do with the problem, looks commented out to me.

    Drew
    Dev-Tips.com || Employee at the Envato Network || My Portfolio

  • #4
    Regular Coder
    Join Date
    Sep 2008
    Location
    Oklahoma
    Posts
    249
    Thanks
    11
    Thanked 13 Times in 13 Posts
    since i have no clue how to write in perl, you could always make a php form processing script.

    also, is the file "AlphaMail.pl" in the same dir and the form script? because the way you have your form code
    Code:
    <form action="/AlphaMail.pl" method="POST"> 
    it is going to the previous dir to run the script.


    seriously though, dont use perl for form, php is much better and easier, imo
    Last edited by owt200x; 12-14-2008 at 08:08 AM.


  •  

    Posting Permissions

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