Jump to content

Notice: Undefined variable: subject in ......


Classified

Recommended Posts

Hi,

i'm trying to use a contact script, and seems like everything else is working fine, but when i test the script i get these 2 messages (At least):

 

Notice: Undefined variable: subject in E:Domains***** \contactfin.php on line 36

 

Notice: Undefined variable: subject in E:\Domains*****\contactfin.php on line 39

 

 

1. <?php

2. //If the form is submitted

3. if(isset($_POST['submit'])) {

4.

5. //Check to make sure that the name field is not empty

6. if(trim($_POST['contactname']) == '') {

7. $hasError = true;

8. } else {

9. $name = trim($_POST['contactname']);

10. }

11.

12. //Check to make sure that the subject field is not empty

13. if(trim($_POST['subject']) == '') {

14. $hasError = true;

15. } else {

16. $subject = trim($_POST['subject']);

17. }

18.

19. //Check to make sure sure that a valid email address is submitted

20. if(trim($_POST['email']) == '')  {

21. $hasError = true;

22. } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {

23. $hasError = true;

24. } else {

25. $email = trim($_POST['email']);

26. }

27.

28. //Check to make sure comments were entered

29. if(trim($_POST['message']) == '') {

30. $hasError = true;

31. } else {

32. if(function_exists('stripslashes')) {

33. $comments = stripslashes(trim($_POST['message']));

34. } else {

35. $comments = trim($_POST['message']);

36. }

37. }

38.

39. //If there is no error, send the email

40. if(!isset($hasError)) {

41. $emailTo = 'info@autovisionfinland.com'; //Put your own email address here

42. $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";

43. $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

44.

45. mail($emailTo, $subject, $body, $headers);

46. $emailSent = true;

47. }

48. }

49 ?>

 

the form with divs and everything comes right after that code, i can copy it too if needed.

 

Any help is appriciated

-Thank you!!

 

 

Link to comment
Share on other sites

sorry,

 

in my site were i added the code i had removed this part

 

 

        //Check to make sure that the subject field is not empty

if(trim($_POST['subject']) == '') {

$hasError = true;

} else {

$subject = trim($_POST['subject']);

}

 

I removed it because i don't want subject an required field, just optional.

So i placed this code above back in the script and now no errors show...

How do i make 'subject' optional?

I removed the options from the var validator = $("#contactform").validate({  in javascript (jquery.validate.pack.js)

 

And another problem occurred, even tho the script says the message was successfully sent... I'm not receiving them.

There are no options in any of the scripts for outgoing smtp or anything, i've tried a plain php contact script which worked fine, and i have activated on host ASP, php5 and SSI. and deactivated Perl Cgi and CGI executables.

I'm really sorry, but i don't know much of these things when it goes outside html and basic php

Link to comment
Share on other sites

i have no idea what a default value is... i googled and found something like this !== null

so i made the optional field like this

 

if(trim($_POST['subject']!== null) == '') {

$hasError = true;

} else {

$subject = trim($_POST['subject']);

}

 

I don't know if that's right, but it worked  :D

 

Thank You!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.