Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

[PHP] Contact Form werkt niet.

Pagina: 1
Acties:
  • 134 views sinds 30-01-2008

  • MrVegeta
  • Registratie: September 2002
  • Laatst online: 28-11 19:45

MrVegeta

! Dolf is rechtvaardig !

Topicstarter
Hoi ik ben bezig met een simpele Contact formulier en die had ik gister ook aan de praat maar toen ging ik het script aanpassen naar mij wensen en nu doet het script het niet meer en ik zou niet weten wat er fout gaat want ik heb het hetzelfde als voordat ik het ging aanpassen.

Het script draaid om 2 php pagina's en 1 config file,

ContactForm/contact.php
ContactForm/inc/contactform.php
ContactForm/inc/config.inc


"contact.php"
Hier zie je de code van contact.php, deze pagina wordt ook gebruikt om uiteindelijk een formulier te versturen. Dit wordt gedaan dmv includes. Ik heb alle paths volledig opgegeven dus daar zal het wel niet aan liggen. Ook alle POST gegevens komen overéén met de gegevens uit "contactform.php".

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?
   include('http://www.no-illusions.nl/ContactForm/inc/config.inc');

    if ($_SERVER['REQUEST_METHOD'] == "POST") {

      $name     = $_POST[name];
      $email    = $_POST[email];
      $company  = $_POST[company];
      $phone    = $_POST[phone];
      $website  = $_POST[website];
      $msg      = $_POST[msg];
      $subject  = $_POST[subject];
      
      // $msg2 is set in config.inc which formats the body of the message
       mail("$adminemail[$who]", "$subjectheader $subject", "$msg2", "From: $email \nReply-To: $email");

      if ($redirecturl != "") {
         header("Location: $redirecturl");
      } else {
         echo "<br><center>$finishedtext</center><br>";
      }

    } else {
      include($script_dir . 'http://www.no-illusions.nl/ContactForm/inc/header.php');
       include($script_dir . 'http://www.no-illusions.nl/ContactForm/inc/contactform.php');
      include($script_dir . 'http://www.no-illusions.nl/ContactForm/inc/footer.php');
    }
?>


"ContactForm/inc/contactform.php".
Hier is het script van het contactform.php dat dus wordt geinclude in "contact.php". Het eerste stukje script kijkt of alle gegevens wel goed zijn ingevuld, als dat niet zo is krijg je een melding (false) en als het klopt word "$finishedtext" uitgevoerd uit het "config.inc" bestand.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<SCRIPT LANGUAGE="JavaScript">
    <!-- Hide code from non-js browsers
    function validate()
    {
        formObj = document.contact;
        if ((formObj.name.value == "") ||
            (formObj.email.value  == "") ||
            (formObj.subject.value  == "") ||
            (formObj.msg.value  == ""))
        {
            alert("You have not filled in all required fields.");
            return false;
        }
        else {
            alert('<? echo $finishedtext; ?>');
            return true;
        }
    }
    // end hiding -->
</SCRIPT>


Het 2e gedeelte van de pagina zorgt voor de layout van het formulier. Ook hier heb ik gebruikt gemaakt van volledige paden en namen. Maar ook hier zie ik niet iets wat niet klopt. De POST gegevens komen overéén met de contact/config gegevens en ook het pad en de naam klopt.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<TABLE BORDER=0 cellpadding=5 cellspacing=0>
  <TR>
    <TD>
       <TABLE BORDER=0 cellpadding=2 cellspacing=0>
         <form action="<? echo $script_url; ?>http://www.no-illusions.nl/ContactForm/contact.php" method="post" name="contact" onSubmit="return validate()">
         <TR>
           <TD>
                <BR>
                <DIV>
                1. Name *<BR>
                <input type=text value='your name' size=50 maxlength=50 name=name class='txtfield'><BR>

                2. Email Adress *<BR>
                <input type='text' value='you@yourname.com' size='50' maxlength='60' name='email'><BR>

                3. Company Name<BR>
                <input type='text' value='your company' size='50' maxlength='50' name='company'><BR>

                4. Phone Number<BR>
                <input type='text' value='(000) 000-0000' size='50' maxlength='32' name='phone'><BR>

                5. Webiste<BR>
                <input type='text' value='http://www.yoursite.com' size='50' maxlength='60' name='website'><BR>

                6. Email to *<BR>
                <select name='who'>
                <option value='1'>Customer Service</option>
                </select><BR>

                7. Subject *<BR>
                <input type='text' value='' size='50' maxlength='60' name='subject'><BR>

                8. Message *<BR>
                <textarea name='msg' rows='7' cols='50'></textarea><BR>

                </DIV>

                <input type='submit' value='submit'>* Field Required<BR>

          </TD>
        </tR>
        </FORM>
      </tABLE>
    </TD>
  </TR>
</tABLE>


"ContactForm/inc/config.inc"
En nu even het laatste config bestand laten zien, want ik denk dat daar dan wel de fout in zit. Hier wordt dus gezegt dat als je geen gebruik maakt van volledige paths het script niet goed kan werken.

"#script directory" is de mapnaam van waar het script zich bevind op de server.
"# script url" is de naam waar het script zich in bevind.
"$finishedtext" is dus wat er wordt weergegeven als het formulier goed werkt en er een mail is verstuurd.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# script name
$scriptname = "Contact Form";

# use full paths
# not using full paths could prevent the script from functioning properly

# script directory 
# no trailing slash
$script_dir = "/httpdocs/ContactForm";

# script url (url to script directory above)
# no trailing slash
$script_url = "http://www.no-illusions.nl/ContactForm";

# variables below corresponds to the Email to * in your contact form
# match the numbers to the value for which option maps to a specific email
# you can add more as long as you keep them in sync

$adminemail[1] = "supersneker@hotmail.com";

# preceeds the subject the user puts in on the contact form
$subjectheader = "[Contact Form]:";

# url the form will redirect to after sending email
$redirecturl = "";

# text that will display if you leave above variable blank
$finishedtext = "Thank you for your inquiry. We will reply ASAP!";

# how the message will show in the email
# you can reorder these how you wish or modify the message itself to your liking
# just be sure and leave the $variables in tact

$msg2 = "
    Name: $name
    Email: $email
    Company: $company
    Phone: $phone
    Website: $website
    Message:$msg
";
?>


Nou jullie zien het, ik heb alle gegevens aangepast zodat alle paden kloppen en ook het mail adres klopt. Mijn server kan mailtjes versturen via dit script want het werkte gisteravond maar nu krijg ik het dus niet meer aan de praat.

http://www.no-illusions.nl/ContactForm/contact.php
Hier zie je het script in actie, als je iets niet invult krijg je daar dus de goede melding van. Als je alles invult krijg je een lege melding (ik heb geen idee wat) en je krijgt ook geen "$finishedtext" te zien.

Dus graag jullie advies over waar het nou mis gaat want ik zie door alle code's het script niet meer.

Geeft steekhoudelijke argumenten terwijl hij niet weet waar het over gaat. BlizzBoys, HD casts van StarCraft II gemaakt door Tweakers! Het begint, Zombiepocalyps


  • Padschild
  • Registratie: September 2004
  • Laatst online: 28-11-2020
Eigenlijk mag er geen support op GoT gegeven op kant en klare scriptjes, daarvoor moet je maar bij de maker aanklopen...

Ik doe toch een gokje:
# use full paths
# not using full paths could prevent the script from functioning properly

# script directory
# no trailing slash
$script_dir = "/httpdocs/ContactForm";
Is geen fullpath naar mijn idee.

PHP:
1
include('http://www.no-illusions.nl/ContactForm/inc/config.inc');


Kan dit zomaar? Een include over internet?

PHP:
1
2
3
include($script_dir . 'http://www.no-illusions.nl/ContactForm/inc/header.php');
       include($script_dir . 'http://www.no-illusions.nl/ContactForm/inc/contactform.php');
      include($script_dir . 'http://www.no-illusions.nl/ContactForm/inc/footer.php');

Volgensmij kan dit al helemaaaal niet, maar het kan aan mij liggen...

Heb je ervaring met PHP en snap je ook wat je aan het doen bent?

[ Voor 3% gewijzigd door Padschild op 29-08-2007 11:27 ]


  • sariel
  • Registratie: Mei 2004
  • Laatst online: 22-05-2024
eeuhm....je include php pagina's via http....dat worden dus geparste pagina's (html ipv php).
PHP:
1
2
3
      include($script_dir . 'http://www.no-illusions.nl/ContactForm/inc/header.php');
       include($script_dir . 'http://www.no-illusions.nl/ContactForm/inc/contactform.php');
      include($script_dir . 'http://www.no-illusions.nl/ContactForm/inc/footer.php');


verder klopt het dat je geen $finishedtext te zien krijgt, omdat bij het opmaken van de pagina $finishedtext nog niet bestaat. dat bestaat pas na het submitten.

Copy.com


  • reddevil
  • Registratie: Februari 2001
  • Laatst online: 06-10 14:25
Als ik het goed begrijp verstuurd ie dus geen mails meer...

Heb je alle data die je wilt versturen in je mail commando op het scherm getoond om te kijken of daar iets raars in staat?

Test is het mail commando met de gegevens hardcoded die je wilt versturen. Levert dat een echte verstuurd mail op?


'and what he said above'

[ Voor 4% gewijzigd door reddevil op 29-08-2007 11:29 ]


  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 12:48

Janoz

Moderator Devschuur®

!litemod

Hier in PRG is het niet de bedoeling dat we support gaan leveren op scripts van derden. Voor problemen moet je maar contact opnemen met Doni Ronquillo, de maker van het script.

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


Dit topic is gesloten.