PHP-based Form Mail (Feedback) Script

Using a PHP script, you may accept feedback from your website visitors and get the results emailed to you. You can use the sample script provided by BigRock and tweak it a bit to suit your requirements.

You would need to change the email address in the field $from to any email address on the domain name on which you are incorporating this script.

Example:

If your domain name is yourdomain.com, then you would define the From email address as some-name@yourdomain.com.

This email address need not be existing on the mail server of yourdomain.com; however, the domain name in the $from field has to be yours.

You may use an email address such as Do_Not_reply@yourdomain.com.

The value in the $mailto field needs to be changed to the email address, where the email containing the data submitted through the form needs to be delivered.

Note

In an attempt to keep a check on abuse from BigRock's Hosting Servers, the following conditions have been set for mail scripts on BigRock's Linux Hosting Servers:

  • The domain name in either the To or the From email address used in the script should be your domain name hosted with BigRock.

    Example: yourdomain.com is hosted with BigRock and yourotherdomain1.com and yourotherdomain2.com are hosted with some other hosting provider.

    • The mail will be sent if

      • the From email address is abc@yourdomain.com and the To email address is xyz@yourotherdomain1.com,

        OR

      • the From email address is abc@yourotherdomain1.com and the To email address is xyz@yourdomain.com.

    • The mail will not be sent if the From email address is abc@yourotherdomain1.com and the To email address is xyz@yourotherdomain2.com.

  • For mail scripts with the From email address as <user>@<server_hostname>, the To email address compulsorily should be an email address on your domain name hosted with BigRock.

    Example: yourdomain.com is hosted with BigRock with parent user yourdo & server name cp-00.webhostbox.net and yourotherdomain1.com is hosted with some other hosting provider.

    With the From email address as yourdo@cp-00.webhostbox.net:

    • The mail will be sent if the To email address is abc@yourdomain.com.

    • The mail will not be sent if the To email address is xyz@yourotherdomain1.com.

Once the visitor provides feedback, he/she can then be re-directed to another page on your website. In order to achieve this, you need to mention the path to the HTML file in the $file field in the script. Alternatively, you can display a message to the visitor thanking him/her for the feedback. Such messages can be displayed in a new page like thanks.htm. Such a page can also contain other information as deemed necessary.

Sample Script

   &lt;?

        $mailto=&quot;xyz@yourdomain.com&quot;;
        $file=&quot;thanks.htm&quot;;
        $pcount=0;
        $gcount=0;
        $subject = &quot;Mail from Enquiry Form&quot;;

        $from=&quot;some-name@yourdomain.com&quot;;
        while (list($key,$val)=each($_POST))
        {
        $pstr = $pstr.&quot;$key : $val \n &quot;;
        ++$pcount;

        }
        while (list($key,$val)=each($_GET))
        {
        $gstr = $gstr.&quot;$key : $val \n &quot;;
        ++$gcount;

        }
        if ($pcount &gt; $gcount)
        {
        $message_body=$pstr;
        mail($mailto,$subject,$message_body,&quot;From:&quot;.$from);

        include(&quot;$file&quot;);
        }
        else
        {
        $message_body=$gstr;

        mail($mailto,$subject,$message_body,&quot;From:&quot;.$from);
        include(&quot;$file&quot;);
        }
        ?&gt;