The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> PHP Contact Form doesn't work
LASALLY
post Sep 22 2014, 10:50 AM
Post #1





Group: Members
Posts: 4
Joined: 22-September 14
Member No.: 21,583



Hi everyone, This is my first post and just saying hi to all and thanks in advance for your interest in my question. I will try to be as specific as I can in explaining the problem.

I'm working on a site from a template and it is a one page responsive bootstrap html file that came with a separate php file for the contact form called send.php

The support that came with the template told me to add this line of code above the contact form within the html file:

<form action="send.php" method="post" id="contactform">

Then add my email address into the php file and upload it to the server, along with everything else. Of course something as simple sounding as that isn't going to work... for me anyways. lol

I ran it through the a validator and while I did flag red for many things, but there wasn't any errors regarding the contact form.

I'm going to include 2 screengrabs of the code and I'm hoping someone can see the missing link. There is a variable in there for "SERVERNAME" which I tried changing to "LOCALHOST" and an IP number that my hosting tech support gave me, but that didn't work either.

What I'm met with is a blank screen after I hit the send button, and I receive no email from the contact form.

So, this is my problem and I appreciate any help or advice sent my way!

P.S. It won't let me upload the jpgs I have as the screen captures to show the code so if someone wants to see them provide me your email address and I will send them to you.

Thanks
L

Thanks in advance
L
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 22 2014, 11:43 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,648
Joined: 10-August 06
Member No.: 7



Can't you post the code as text? That's far more convenient than looking at a picture anyway.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
LASALLY
post Sep 23 2014, 09:15 AM
Post #3





Group: Members
Posts: 4
Joined: 22-September 14
Member No.: 21,583



QUOTE(Christian J @ Sep 22 2014, 12:43 PM) *

Can't you post the code as text? That's far more convenient than looking at a picture anyway.


Sure, here is the code that is within the html file:

<!-- start contact area -->
<section id="contactArea">
<div class="container">

<h1 class="text-center">Contact us</h1>

<div class="row">
<form action="send.php" method="post" id="contactform">

<div class="col-sm-4">

<p><label>Address:</label><address> xxx,<br> xxx, <br> xxx <br>xxxxxxx</address></p>
<p><label>Phone:</label><address>+000-000-0000 <br></address></p>

<p>
<a class="btn btn-outline-inverse"><i class="fa fa-facebook"></i></a>
<a class="btn btn-outline-inverse"><i class="fa fa-flickr"></i></a>
<a class="btn btn-outline-inverse"><i class="fa fa-github"></i></a>
<a class="btn btn-outline-inverse"><i class="fa fa-google-plus"></i></a>
<a class="btn btn-outline-inverse"><i class="fa fa-linkedin"></i></a>
<a class="btn btn-outline-inverse"><i class="fa fa-twitter"></i></a>
</p>

</div>

<div class="col-sm-4">

<p><label>Name</label><br><input type="text" placeholder="Full Name" class="form-control"></p>
<p><label>Email Address</label><br><input type="email" placeholder="Email Address" class="form-control"></p>
<p><label>Phone</label><br><input type="tel" placeholder="Phone Number" class="form-control"></p>

</div>

<div class="col-sm-4">

<p><label>Comments</label><br><textarea cols="10" rows="5" placeholder="Type your message here..." class="form-control"></textarea></p>
<p><input type="submit" class="btn btn-outline-inverse" value="submit"></p>

</div>

</form>
</div>

</div>

</section>
<!-- end contact area -->




And here is the code for the php send file:

<? error_reporting(0);

$mail = "myemailaddygoeshere";

if($_POST['message']) {
$message = "<h2>Hello here is a message from ".$_SERVER[SERVER_NAME]."</h2><hr>
<p><strong>Name:</strong> ".$_POST['name']."</p>
<p><strong>Email:</strong> ".$_POST['email']."</p>
<p><strong>Message:</strong> ".$_POST['message']."</p>";
$subject="Request for Information: ".$_POST['subject'];
mail($mail, $subject, $message, "Content-type: text/html; charset=utf-8 \r\n"); //email
echo 'AAAAAAAAAAAAAAA';
}
?>


Any help would be very much appreciated, thank you Christian J.

Leslie



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 23 2014, 01:54 PM
Post #4


.
********

Group: WDG Moderators
Posts: 9,648
Joined: 10-August 06
Member No.: 7



QUOTE
There is a variable in there for "SERVERNAME"

That shouldn't be changed, it's a predefined PHP variable.

But, each INPUT and TEXTAREA element in the form needs a NAME attribute that corresponds with the one used by the $_POST variables in the PHP script. For example:

CODE
<input type="text" name="foo" placeholder="Full Name" class="form-control">

in the form corresponds with:
CODE
$_POST['foo']

in the PHP script. Sidenotes:

- Since the email contains HTML, you need to sanitize all user-submitted form data so that clumsy or malicious users can't inject their own HTML. Use e.g. PHP's htmlspecialchars function for that, like this:

CODE
htmlspecialchars($_POST['name'])


- Your LABEL elements won't work the way they are used now, you should put the form elements inside them. See http://www.htmlhelp.com/reference/html40/forms/label.html



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
LASALLY
post Sep 23 2014, 02:59 PM
Post #5





Group: Members
Posts: 4
Joined: 22-September 14
Member No.: 21,583



Thank you for this Christian J!! I'll see how I make out and let you know. : )
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 23 2014, 04:07 PM
Post #6


.
********

Group: WDG Moderators
Posts: 9,648
Joined: 10-August 06
Member No.: 7



QUOTE(LASALLY @ Sep 23 2014, 04:15 PM) *

$message = "<h2>Hello here is a message from ".$_SERVER[SERVER_NAME]."</h2><hr>

The SERVER_NAME part should be in quotes:

CODE
$_SERVER['SERVER_NAME']

But if you want you can simply replace it with any plain text message, like:

CODE
$message = "<h2>Hello here is a message from www.yoursite.com</h2><hr>



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
LASALLY
post Sep 24 2014, 06:53 PM
Post #7





Group: Members
Posts: 4
Joined: 22-September 14
Member No.: 21,583



QUOTE(Christian J @ Sep 23 2014, 05:07 PM) *

QUOTE(LASALLY @ Sep 23 2014, 04:15 PM) *

$message = "<h2>Hello here is a message from ".$_SERVER[SERVER_NAME]."</h2><hr>

The SERVER_NAME part should be in quotes:

CODE
$_SERVER['SERVER_NAME']

But if you want you can simply replace it with any plain text message, like:

CODE
$message = "<h2>Hello here is a message from www.yoursite.com</h2><hr>




Hi, Yes, I have fixed the quotes since this... still working on it. biggrin.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 16th April 2024 - 07:20 AM