PHP Script not working, check please...

AFPoster

macrumors 68000
Original poster
Jul 14, 2008
1,522
101
Charlotte, NC
So I created a Contact Us page and for some reason my contact.php script isn't sending anything back to me.
PHP 5.3 on my server fyi

Contact.html
Code:
 <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>
The code doesn't open with <? since it's created in Coda. Should I change this? If so I get red text on a lot of the commands.
Contact.php:

Code:
<?php

$name = $_POST['name'];
$email = $_POST['e-mail'];
$phone = $_POST['phone'];
$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 .= “Company: <b>” . $name . “</b><br>”;
$content .= “Name: <b>” . $email . “</b><br>”;
$content .= “Phone: <b>” . $phone . “</b><br>”;
$content .= “E-mail: <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>
 
Last edited:

Darth.Titan

macrumors 68030
Oct 31, 2007
2,719
328
Austin, TX
You answered your own question. A PHP script won't execute without the opening <?php. Your server is seeing it as a plain text file.

The red text you're seeing in Coda is called "Syntax Highlighting". It helps you differentiate between different commands, variable types, etc. in your code. Coda puts it in when you give it an indication of what type of file you're editing, like by adding the <?php opener.

P.S., your script still won't work. In your HTML form you specify method="post", but your PHP script is trying to use $_GET variables. Change all occurrences of $_GET to $_POST in your PHP.

EDIT You also haven't assigned any name values to your html form fields. The PHP script can't get the values without field names.

Your scripts need a lot of work...
 

AFPoster

macrumors 68000
Original poster
Jul 14, 2008
1,522
101
Charlotte, NC
You answered your own question. A PHP script won't execute without the opening <?php. Your server is seeing it as a plain text file.

The red text you're seeing in Coda is called "Syntax Highlighting". It helps you differentiate between different commands, variable types, etc. in your code. Coda puts it in when you give it an indication of what type of file you're editing, like by adding the <?php opener.

P.S., your script still won't work. In your HTML form you specify method="post", but your PHP script is trying to use $_GET variables. Change all occurrences of $_GET to $_POST in your PHP.

EDIT You also haven't assigned any name values to your html form fields. The PHP script can't get the values without field names.

Your scripts need a lot of work...
Changes have been made in the PHP script. What do you mean by assigning name values? I'm looking online but all I find is "cf_name" but no description on what "cf" means or does.


You also wouldn't happen know how to do this by any chance:

In html you can <a href> to link to another page when you click on text or an image. Is their any way to do that in CSS3 that will affect the image placed in html?
 
Last edited:

stevooo

macrumors newbie
Mar 23, 2008
8
0
What do you mean by assigning name values? I'm looking online but all I find is "cf_name" but no description on what "cf" means or does.
Each input needs a name which should correspond to the names you've used in your php files _POST lines.

Code:
<input type="text" value="" [B]name="name"[/B] /> ...is retrieved by $_POST['[B]name[/B]']
<input type="text" value="" [B]name="e-mail"[/B] /> ...is retrieved by $_POST['[B]e-mail[/B]']
etc. etc.
 

Darth.Titan

macrumors 68030
Oct 31, 2007
2,719
328
Austin, TX
You also wouldn't happen know how to do this by any chance:

In html you can <a href> to link to another page when you click on text or an image. Is their any way to do that in CSS3 that will affect the image placed in html?
Not sure I understand the question, it sounds like what you want would be more likely accomplished using Javascript than CSS.
 

AFPoster

macrumors 68000
Original poster
Jul 14, 2008
1,522
101
Charlotte, NC
Each input needs a name which should correspond to the names you've used in your php files _POST lines.

Code:
<input type="text" value="" [B]name="name"[/B] /> ...is retrieved by $_POST['[B]name[/B]']
<input type="text" value="" [B]name="e-mail"[/B] /> ...is retrieved by $_POST['[B]e-mail[/B]']
etc. etc.
Code is updated in my initial post. I don't need to add the ":" after Name, E-Mail, etc do I.



Not sure I understand the question, it sounds like what you want would be more likely accomplished using Javascript than CSS.
This is what I have: Can I add "background:url(http://www.mycompany.com) to make it affect the "background:url(../images/logo.png) so that if they click the logo it takes them to that link.
Code:
h1 {
	font-size:34px;
	line-height:1.2em;
	color:#fff;
	font-weight:normal;
	background:url(../images/logo.png) no-repeat 0 0;
	padding:6px 0 8px 69px;
	position:absolute;
	left:39px;
	top:6px;
 
Last edited:

Darth.Titan

macrumors 68030
Oct 31, 2007
2,719
328
Austin, TX
This is what I have: Can I add "background:url(http://www.mycompany.com) to make it affect the "background:url(../images/logo.png) so that if they click the logo it takes them to that link.
Code:
h1 {
	font-size:34px;
	line-height:1.2em;
	color:#fff;
	font-weight:normal;
	background:url(../images/logo.png) no-repeat 0 0;
	padding:6px 0 8px 69px;
	position:absolute;
	left:39px;
	top:6px;
No you can't. Just wrap an anchor around your h1 text:
PHP:
<h1><a href="http://www.mycompany.com">Your Heading text</a></h1>
and change your css a bit:
PHP:
h1 {
	font-size:34px;
	line-height:1.2em;
	font-weight:normal;
	background:url(../images/logo.png) no-repeat 0 0;
	padding:6px 0 8px 69px;
	position:absolute;
	left:39px;
	top:6px;
}
h1 a {
	color:#fff;
	text-decoration: none;
}
 

AFPoster

macrumors 68000
Original poster
Jul 14, 2008
1,522
101
Charlotte, NC
No you can't. Just wrap an anchor around your h1 text:
PHP:
<h1><a href="http://www.mycompany.com">Your Heading text</a></h1>
and change your css a bit:
PHP:
h1 {
	font-size:34px;
	line-height:1.2em;
	font-weight:normal;
	background:url(../images/logo.png) no-repeat 0 0;
	padding:6px 0 8px 69px;
	position:absolute;
	left:39px;
	top:6px;
}
h1 a {
	color:#fff;
	text-decoration: none;
}
Php is cleaned up and the anchor didn't work, no worries I'll try and find something. Thanks for the help! Now just doing the final clean up on the contact form.
 

Acejam2k

macrumors regular
Jul 16, 2008
233
9
So I created a Contact Us page and for some reason my contact.php script isn't sending anything back to me.
PHP 5.3 on my server fyi

Contact.html
Code:
 <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>
The code doesn't open with <? since it's created in Coda. Should I change this? If so I get red text on a lot of the commands.
Contact.php:

Code:
<?php

$name = $_POST['name'];
$email = $_POST['e-mail'];
$phone = $_POST['phone'];
$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 .= “Company: <b>” . $name . “</b><br>”;
$content .= “Name: <b>” . $email . “</b><br>”;
$content .= “Phone: <b>” . $phone . “</b><br>”;
$content .= “E-mail: <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>

I'm still learning PHP myself - but your PHP mail(); function clearly is addressing the message to $recipient, yet you don't define $recipient anywhere. You did however, define $mail_to. I would also change the name values of the text fields on the HTML page to match the same casing as the PHP scripts expects. (ie: lowercase)
 

AFPoster

macrumors 68000
Original poster
Jul 14, 2008
1,522
101
Charlotte, NC
I'm still learning PHP myself - but your PHP mail(); function clearly is addressing the message to $recipient, yet you don't define $recipient anywhere. You did however, define $mail_to. I would also change the name values of the text fields on the HTML page to match the same casing as the PHP scripts expects. (ie: lowercase)
I removed $recipient unless there is a reason for me to have it.

Code:
<?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>
 

Acejam2k

macrumors regular
Jul 16, 2008
233
9
I removed $recipient unless there is a reason for me to have it.

Code:
<?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>
You're still missing it I believe. The mail() function doesn't know where to send this information that you have.

Took at look at some documentation on the mail function. Simply put, a correct example would be:

mail($to, $subject, $message);
mail('caffeinated@example.com', 'My Subject', $message);

The first input value of the mail function is used as the delivery endpoint. It's where the information is sent to. Therefore, you need to put all of your data together in another string, and input that as the 3rd value. (call it $message or whatever) You can't just throw a bunch of variables inside the parenthesis, and expect for everything to be magically delivered.

Read this: http://php.net/manual/en/function.mail.php

EDIT: Sounds like this is you: http://forum.cmsmadesimple.org/viewtopic.php?t=59226&p=271277
 

AFPoster

macrumors 68000
Original poster
Jul 14, 2008
1,522
101
Charlotte, NC
You're still missing it I believe. The mail() function doesn't know where to send this information that you have.

Took at look at some documentation on the mail function. Simply put, a correct example would be:

mail($to, $subject, $message);
mail('caffeinated@example.com', 'My Subject', $message);

The first input value of the mail function is used as the delivery endpoint. It's where the information is sent to. Therefore, you need to put all of your data together in another string, and input that as the 3rd value. (call it $message or whatever) You can't just throw a bunch of variables inside the parenthesis, and expect for everything to be magically delivered.

Read this: http://php.net/manual/en/function.mail.php
I read the article it helps but I still think I'm having a disconnect. I think this is because the other script I have works and it doesn't have everything that is being requested. I'm putting the changes in as we speak.