Problem with contact form mailing with php

Hi all, i just registered since i cant resolve this myself and im on a really tight schedule.

anyway im building this website and i’ve got the form as follows

<form id="form1"  action="contact.php" method="post">
						<div class="success"> Contact form submitted!<br><strong>We will be in touch soon.</strong> </div>
						<fieldset>
							<label class="name">
								<input type="text" value="Name:">
								<span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span> </label>							
							<label class="email">
								<input type="email" value="E-mail:">
								<span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span> </label>
							<label class="phone">
								<input type="tel" value="Phone:">
								<span class="error">*This is not a valid phone number.</span> <span class="empty">*This field is required.</span> </label>
							<label class="message">
								<textarea>Message:</textarea>
								<span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>							
							<div class="btns und"><a href="#" class="btn" data-type="reset">clear</a><a href="#" class="btn" data-type="submit">submit</a></div>
						</fieldset>
					</form>

and i found this code snippet online but i cant get it to work…

<?php
$Name = $_REQUEST['name'];
$Email = $_REQUEST['email'];
$Phone = $_REQUEST['phone'];
$Message = $_REQUEST['message'];

/*Sending Email*/

$to = "myemail@mail.com";
$subject = "Question about a service";
$from = $Name;
Name = $Name
Email = $Email
Phone = $Phone
Message = $Message;



if(mail($to, $subject, $message, "From: $from"))
echo "Mail sent";
else
echo "Mail send failure - message not sent";
?>

i actually think my submit button or link whatever… isnt doing anything…

Can anyone please assist me because its driving me crazy…

yes i tried searching the net and all i can find are different forms with php files but i need to get my form working because of the style used

thank you all in advance

Without loading up your stuff and playing trial and error I won’t be able to solve it either. But her is my script A to Z for you. Copy and paste http://www.websitecodetutorials.com/code/php/how-to-html-form-with-php-js-captcha-validation.php

Or if you want a 2 second one here is this one too http://www.websitecodetutorials.com/code/php/one-webpage-php-contact-form.php.

Hi ic3manbl. Welcome to the forums. :slight_smile:

That’s a pretty crummy script you have there. It has no defense against spammers. But one reason it’s not working for you is that the HTML inputs are lacking the name=“” attribute, which sends information to the PHP script. For example, the first label/input should be something like this:

<label for="username" class="name">
    <input type="text" id="username" [COLOR="#FF0000"]name="name"[/COLOR] value="Name:">

Yes i fixed that part, forgot it… but still no luck… when i click on submit nothing happens at all…

OK, just to be sure, show us what you have now.

The next question is: where is contact.php in relation to your contact page? At the moment, it should be in the same folder.

I actually fixed it, it was missing onclick(Submit()) now it sends the email and all… but can i stop it from opening a blank page ? can i instead make it pop an alert window “Mail sent” OK in the existing window

That’s JavaScript, though, which is pretty unreliable. Do you also have a JS file in there?

it seems to work now opposed to before using it :confused: … anyway heres the code if it helps:

<form id="form1"  action="contact.php" method="POST">
						<div class="success"> Contact form submitted!<br><strong>We will be in touch soon.</strong> </div>
						<fieldset>
							<label class="name">
								<input type="text" name="name" value="Name:">
								<span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span> </label>							
							<label class="email">
								<input type="email" name="email" value="E-mail:">
								<span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span> </label>
							<label class="phone">
								<input type="tel" name="phone" value="Phone:">
								<span class="error">*This is not a valid phone number.</span> <span class="empty">*This field is required.</span> </label>
							<label class="message" name="message" >
								<textarea name="message">Message:</textarea>
								<span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>	
                          <input type="button" value="Submit Form" onclick="submit();">
 
						</fieldset>
					</form>

And the PHP file which i edited for now just to show me if it sent the mail :

 <?php 
$Name = $_REQUEST['name']; 
$Email = $_REQUEST['email']; 
$Phone = $_REQUEST['phone']; 
$Message = $_REQUEST['message']; 

/*Sending Email*/ 

$to = "xxxxxxx@xx.com";
$subject = "Inquiry";
$from = $Email;
$message =
"Message from : $Name
  Senders E-Mail : $Email
  Senders Phone Number : $Phone
  
  Message : 
  $Message

";
$headers = "From: $Email"."\\r\
";
$headers .= 'Cc: xxxxx@xxxxx.com' . "\\r\
";

if(mail($to, $subject, $message,$headers))
echo "Success";
else echo "Fail"
?>

O, right, I didn’t notice you were using input type=“button”. It would be better to use somethng like this:

<input type="[COLOR="#FF0000"]submit[/COLOR]" value="Submit Form">

FYI you should not even bother getting a script working with no protection. 2 months from now you will only be looking for better once you or your client start getting 100 spams a week. If its worth doing, it’s worth doing right.

[ot]

Yes, a case of “don’t say we didn’t warn you.” :smiley: [/ot]