Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Comments Form

Featured Replies

Hi there, I was wondering if someone could help me. I am trying to create a basic comments form script attaching a PHP script to a HTML web form. I am using the LAMP configuration. I have enabled the mail function in the PHP.ini file on the sendmail_path line for linux so I know my configuration is correct. This is a temporary "localhost" setup which eventually will be posted on an internet server and I just cannot get it to work. Can someone have a look at my code and see where I am going wrong? I would really appreciate anyones help i've been sat thinking about it for days lol.

 

html webform

<html>
<head>
<title>Feedback Form</title>
<body>
 <form action="feedback.php" method="post">
 Name:<input type="text" name="username" size="30">
 <br>
 <br>
 E Mail:<input type="text" name="useraddress" size="30">
 <textarea name="comments" cols="30" rows="5"></textarea>
 <br>
 <input type="submit" value="send form">
</form>
</body>
</html>

 

form handler script

<?php
     $username = $_POST['username'];
     $useraddress = $_POST['useraddress'];
     $comments = $_POST['comments'];

     $to = "joe@white-fire.co.uk";
     $re = "Website Feedback";
     $msg = $comments;
     mail( $to, $re, $msg );
?>

<html>
<head>
<title>Message Recieved</title>
<body>
 <h3>Thankyou for your comments</h3>
 message recieved from <?php echo( $username ); ?>
 <br>
 Reply to <?php echo( $useraddress ); ?>
 </body>
</html>

 

php.ini config

[mail function]
; For Win32 only.
; SMTP = smtp.streamline.net
smtp_port = 25

; For Win32 only.
; sendmail_from = joe@white-fire.co.uk

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = -t -i

 

Sorry to bombard you guys with code I know how annoying it is when people do that on forums but like I say, I would appreciate anyone who tries to help

Hi there, I was wondering if someone could help me. I am trying to create a basic comments form script attaching a PHP script to a HTML web form. I am using the LAMP configuration. I have enabled the mail function in the PHP.ini file on the sendmail_path line for linux so I know my configuration is correct. This is a temporary "localhost" setup which eventually will be posted on an internet server and I just cannot get it to work. Can someone have a look at my code and see where I am going wrong? I would really appreciate anyones help i've been sat thinking about it for days lol.

 

html webform

<html>
<head>
<title>Feedback Form</title>
<body>
 <form action="feedback.php" method="post">
 Name:<input type="text" name="username" size="30">
 <br>
 <br>
 E Mail:<input type="text" name="useraddress" size="30">
 <textarea name="comments" cols="30" rows="5"></textarea>
 <br>
 <input type="submit" value="send form">
</form>
</body>
</html>

 

form handler script

<?php
     $username = $_POST['username'];
     $useraddress = $_POST['useraddress'];
     $comments = $_POST['comments'];

     $to = "joe@white-fire.co.uk";
     $re = "Website Feedback";
     $msg = $comments;
     mail( $to, $re, $msg );
?>

<html>
<head>
<title>Message Recieved</title>
<body>
 <h3>Thankyou for your comments</h3>
 message recieved from <?php echo( $username ); ?>
 <br>
 Reply to <?php echo( $useraddress ); ?>
 </body>
</html>

 

php.ini config

[mail function]
; For Win32 only.
; SMTP = smtp.streamline.net
smtp_port = 25

; For Win32 only.
; sendmail_from = joe@white-fire.co.uk

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = -t -i

 

Sorry to bombard you guys with code I know how annoying it is when people do that on forums but like I say, I would appreciate anyone who tries to help

 

To start with if you wish to have SMTP enabled you need to uncomment smtp_from and SMTP =

 

If you wish to use sendmail (which won't work on windows) you can usally just remove the value you gave it.

 

 

e.g. for windows

 

[mail function]
; For Win32 only.

SMTP = smtp.yourserver.com
smtp_port = 25

; For Win32 only.
sendmail_from = joe@white-fire.co.uk

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; sendmail_path =

 

 

e.g. for unix (default)

 

[mail function]
; For Win32 only.

SMTP = smtp.yourserver.com
;smtp_port = 25

; For Win32 only.
;sendmail_from = joe@white-fire.co.uk

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path =

 

I've only read your php.ini config and haven't looked at your code.. i'll take a look at your code when i'm not at work :)

Played around with your form for you. Please make sure you check for header injection.

 

<?php
$submit         =   (isset($_POST['submit'])) ? TRUE : FALSE;
$username       =   (isset($_POST['username'])) ? strip_tags($_POST['username']) : FALSE;
$useraddress    =   (isset($_POST['useraddress'])) ? strip_tags($_POST['useraddress']) : FALSE;
$comments       =   (isset($_POST['comments'])) ? strip_tags($_POST['comments']) : FALSE;

$success        =   FALSE;
$errors         =   array();

// They clicked submit?
if ($submit)
{
   if (!$username || !$useraddress || !$comments)
   {
       if (!$username)
       {
           $errors[]   =   'Please fill in your username';
       }

       if (!$useraddress)
       {
           $errors[]   =   'Please fill in your address';
       }

       if (!$comments)
       {
           $errors[]   =   'Please enter some comments';
       }
   }
   else
   {
       // Send email
       $to     =   'joe@white-fire.co.uk';
       $re     =   'Website Feedback';

       // Headers
       $headers =  'From: youremail@test.com' . "\r\n";

       // Send email
       mail($to,$re,$comments,$headers);

       // Templating vars
       $errors     =   FALSE;
       $success    =   TRUE;
   }
}
?>

<?php if($success): ?>
<html>
<head>
<title>Message Recieved</title>
<body>
 <h3>Thankyou for your comments</h3>
 message recieved from <?php echo( $username ); ?>
 <br>
 Reply to <?php echo( $useraddress ); ?>
 </body>
</html>

<?php else: ?>

<html>
<head>
<title>Feedback Form</title>
<body>
   <?php if(count($errors) != 0): ?>
   <div class="errors">
   <?php echo implode('<br />',$errors); ?>
   </div>
   <?php endif; ?>
 <form action="" method="post">
 Name:<input type="text" name="username" size="30">
 <br>
 <br>
 E Mail:<input type="text" name="useraddress" size="30">
 <textarea name="comments" cols="30" rows="5"></textarea>
 <br>
 <input type="submit" value="send form" name="submit">
</form>
</body>
</html>
<?php endif; ?>

  • Author

Thankyou for your help. It really is appreciated. Although I haven't got round to editing anything yet I will let you know the outcome in due course. I am setting up a test server as we speak to give it a go this weekend from home. I will let you know the outcome! Thanks again!

  • Author

I just want to say thanks for the advice. With your help the CGI script is up and running on the server and is happily routing the information I need to my e-mail. Thanks again

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.