Page 1 of 1

PHP Script for Contact Form not working in CMSMS

Posted: Wed Jan 25, 2012 8:19 pm
by fr0z3ng33k
Had a site hosted by GoDaddy and this script worked along with the html version of the site. Since I've transferred it over to CMSMS (1.10.3) it no longer works. Am I missing something in my code? Server is running PHP5.3 - Thanks for the help and I apologize for my lack of knowledge.

html site:

Code: Select all

<section id="content">
            <article>
            	<h2>Contact <span>Form</span></h2>
              <form id="contacts-form" action="contact.php" method="post">
                <fieldset>
                  <div class="field">
                    <label>Name:</label>
                    <input type="text" value="" name="Name" />
                  </div>
                  <div class="field">
                    <label>E-mail:</label>
                    <input type="text" value="" name="E-mail" />
                  </div>
                  <div class="field">
                    <label>Phone:</label>
                    <input type="text" value="" name="Phone" />
                  </div>
                  <div class="field">
                    <label>Company:</label>
                    <input type="text" value="" name="Company" />
                  </div>
                  <div class="field">
                    <label>Message:</label>
                    <textarea></textarea>
                  </div>
                  <div><a href="thankyou.html" onclick="document.getElementById('contacts-form').submit()">Send Your Message!</a></div>
                </fieldset>
              </form>
            </article> 
          </section>
        </div>
      </div>
    </div>
  </div>
PHP Script:

Code: Select all

<?php

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$company = $_POST['company'];
$your_message = $_POST['message'];

$headers .= ‘Content-type: text/html; charset=iso-8859-1′;

$content = “<__html><head><title>Contact letter</title></head></__body><br>”;
$content .= “Name: <b>” . $name . “</b><br>”;
$content .= “Email: <b>” . $email . “</b><br>”;
$content .= “Phone: <b>” . $phone . “</b><br>”;
$content .= “Company: <b>” . $company . “</b><br><hr><br>”;
$content .= $your_message;
$content .= “<br><__body></__html>”;

$mail_to = 'info@mycompany.com';
$subject = 'Message from a site visitor '.$field_name;

mail($recipient,$subject,$content,$headers);
?>
<__html>
</__body bgcolor=”#282E2C”>
<div align=”center” style=”margin-top:60px;color:#FFFFFF;font-size:11px;font-family:Tahoma;font-weight:bold”>
Your message was sent. Thank you.
</div>
<__body>
</__html>
<__script__>resizeTo(300, 300)</__script>

Re: PHP Script for Contact Form not working in CMSMS

Posted: Wed Jan 25, 2012 9:26 pm
by scelle
I don't know why is this script not working. I just wonder why you don't use the Form Builder module for creating forms? It's a core module (which means a great support and certain maintenance) that is widely used on CMS MS sites. And it's way, way, way simpler than this.

Re: PHP Script for Contact Form not working in CMSMS

Posted: Wed Jan 25, 2012 11:29 pm
by fr0z3ng33k
I'd agree but it's what the boss wants so the boss gets it. Thanks for looking at it though!

Re: PHP Script for Contact Form not working in CMSMS

Posted: Thu Jan 26, 2012 12:07 am
by Wishbone
What happens when you submit the form?

Re: PHP Script for Contact Form not working in CMSMS

Posted: Thu Jan 26, 2012 1:51 pm
by Jos
fr0z3ng33k wrote:I'd agree but it's what the boss wants so the boss gets it. Thanks for looking at it though!
Does the boss wants you to use this "script" or does the boss wants a contact form on the site that works properly.
If it's the first, I think he is not that good a boss :P

Re: PHP Script for Contact Form not working in CMSMS

Posted: Thu Jan 26, 2012 2:03 pm
by fr0z3ng33k
Wishbone wrote:What happens when you submit the form?
It takes me to the ThankYou.html page but I never receive it in my inbox.
Jos wrote:
fr0z3ng33k wrote:I'd agree but it's what the boss wants so the boss gets it. Thanks for looking at it though!
Does the boss wants you to use this "script" or does the boss wants a contact form on the site that works properly.
If it's the first, I think he is not that good a boss :P
The boss wants me to use his script. Mainly because for this site he is using CMSMS but his other sites aren't. So he wants the same working script on everything.

Re: PHP Script for Contact Form not working in CMSMS

Posted: Thu Jan 26, 2012 2:11 pm
by Jos

Code: Select all

$mail_to = 'info@mycompany.com';
$subject = 'Message from a site visitor '.$field_name;

mail($recipient,$subject,$content,$headers);
$field_name is not set anywhere
$recipient is not set anywhere

Re: PHP Script for Contact Form not working in CMSMS

Posted: Thu Jan 26, 2012 7:52 pm
by fr0z3ng33k
Jos wrote:

Code: Select all

$mail_to = 'info@mycompany.com';
$subject = 'Message from a site visitor '.$field_name;

mail($recipient,$subject,$content,$headers);
$field_name is not set anywhere
$recipient is not set anywhere

How does this look and do I need to define name, email, etc (put it in the code for now but I can remove it).

Code: Select all

<?php

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$company = $_POST['company'];
$your_message = $_POST['message'];

$headers .= ‘Content-type: text/html; charset=iso-8859-1′;

$content = “<__html><head><title>Contact letter</title></head></__body><br>”;
$content .= “Name: <b>” . $name . “</b><br>”;
$content .= “Email: <b>” . $email . “</b><br>”;
$content .= “Phone: <b>” . $phone . “</b><br>”;
$content .= “Company: <b>” . $company . “</b><br><hr><br>”;
$content .= $your_message;
$content .= “<br><__body></__html>”;

$mail_to = 'info@mycompany.com';
$subject = 'Message from a site visitor ';

mail($name,$phone,$email,$company,$your_message,$subject,$content,$headers);
?>
<__html>
</__body bgcolor=”#282E2C”>
<div align=”center” style=”margin-top:60px;color:#FFFFFF;font-size:11px;font-family:Tahoma;font-weight:bold”>
Your message was sent. Thank you.
</div>
<__body>
</__html>
<__script__>resizeTo(300, 300)</__script>

Re: PHP Script for Contact Form not working in CMSMS

Posted: Thu Jan 26, 2012 8:52 pm
by Jos
This might help: http://nl2.php.net/manual/en/function.mail.php

The real advise is still: use FormBuilder and you'll have your form running in minutes.

Re: PHP Script for Contact Form not working in CMSMS

Posted: Fri Jan 27, 2012 2:25 pm
by fr0z3ng33k
Jos wrote: The real advise is still: use FormBuilder and you'll have your form running in minutes.
If I use that will it work on sites not running CMSMS? Boss wants consistency.

Re: PHP Script for Contact Form not working in CMSMS

Posted: Fri Jan 27, 2012 2:39 pm
by scelle
Sure it will! You can set field ids, names etc... And you can create a custom template for the sent message. Try it, it's a great module!

Even better, show it to your boss, he'll love you for making his life A LOT easier! ;)

Re: PHP Script for Contact Form not working in CMSMS

Posted: Fri Jan 27, 2012 4:37 pm
by Wishbone
If some of your sites are not using CMSMS, there's not much consistency anyways. Use that script on non-CMSMS sites. Use what's best for CMSMS (FormBuilder) on CMSMS sites.

Re: PHP Script for Contact Form not working in CMSMS

Posted: Fri Jan 27, 2012 5:23 pm
by Jos
fr0z3ng33k wrote:Boss wants consistency.
I guess boss only cares about the email that is generated. You can make that look exactly the same as your other sites

Re: PHP Script for Contact Form not working in CMSMS

Posted: Fri Jan 27, 2012 8:55 pm
by fr0z3ng33k
Jos wrote:
fr0z3ng33k wrote:Boss wants consistency.
I guess boss only cares about the email that is generated. You can make that look exactly the same as your other sites
good to hear thanks all!