-
1. Re: My php contact form won't work. HELP!?
Rob Hecker2 Dec 2, 2014 9:11 AM (in response to trenholme90)Try this:
<!doctype html>
<html>
<?php
if ($_POST){
if (!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)){
$message="Please provide a correct email address";} else {
$name = strip_tags($_POST['name']);
$company_name = strip_tags($_POST['company_name']);
$telephone = strip_tags($_POST['telephone']);
$email = $_POST['email'];
$comments = strip_tags($_POST['comments']);
$to = 'trenholme90@hotmail.com';
$subject = 'Contact form submitted.';
$body = $name. "\n" .$comments;
$headers = 'From: ' .$email;
if (mail($to, $subject, $body, $headers)) {
echo 'Thanks for contacting us. We\'ll be in touch soon!';
} else {
$message = 'Sorry an error occurred. Please try again later.';
}
}}
?>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php echo "<p style='color:red'>$message</p>"; ?>
<div class="contact_form">
<form id="contactform" action="contact.php" method="post">
<p>Name:<br/><input name="name" type="text" required /></p>
<p>Company Name: <br/><input name="company_name" type="text" required/></p>
<p>Telephone: <br/><input name="telephone" type="tel" required/></p>
<p>Email: <br/><input name="email" type="email" required/></p>
<p>Comments: <br/><textarea name="comments" required/> </textarea></p>
<input type="submit" name="submit" value="Send!"/>
</form>
</div>
</body>
</html>
-
2. Re: My php contact form won't work. HELP!?
trenholme90 Dec 2, 2014 9:29 AM (in response to trenholme90)Thanks Rob, I appreciate the help but it didn't work. The message said it was sent successfully ("Thanks for contacting us. We'll be in touch soon" appeared at the top of the page) But no information was sent anywhere. No email's received.
-
3. Re: My php contact form won't work. HELP!?
trenholme90 Dec 2, 2014 9:31 AM (in response to trenholme90)Just went on my website and it says under the contact form "Connection failed: Access denied for user 'root'@'localhost' (using password: YES)"
-
4. Re: My php contact form won't work. HELP!?
osgood_ Dec 2, 2014 9:37 AM (in response to trenholme90)trenholme90 wrote:
Just went on my website and it says under the contact form "Connection failed: Access denied for user 'root'@'localhost' (using password: YES)"
That is nothing to do with the form that message implies you are trying to connect to a database but dont have the correct 'privilages' so are being denied access.
-
5. Re: My php contact form won't work. HELP!?
Rob Hecker2 Dec 2, 2014 9:57 AM (in response to trenholme90)Well, you know know that it works as far as thinking the email has been sent. Check your spam folder to make sure the emails are not being delivered there.
Add the following right after the mail() line to check your variables
echo "to $to subject: $subject body: $body headers $headers";
As for the database error Osgood mentioned, it doesn't seem like that has anything to do with the mail script, and isn't preventing it from running.
-
6. Re: My php contact form won't work. HELP!?
trenholme90 Dec 3, 2014 3:27 AM (in response to trenholme90)Ok thanks. The variables work, as they appeared at the top of the screen, but still no email. I don't know what else to do.
-
7. Re: My php contact form won't work. HELP!?
Ben Pleysier Dec 3, 2014 3:36 AM (in response to trenholme90)Is your system equipped with a mail server?
The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP implementation allows email sending on Windows platforms without a local mail server.
See for more PHPMailer/PHPMailer · GitHub
-
8. Re: My php contact form won't work. HELP!?
trenholme90 Dec 3, 2014 3:43 AM (in response to trenholme90)Well, I'm working on a mac so yeah I have the usual mail application.
-
9. Re: My php contact form won't work. HELP!?
Ben Pleysier Dec 3, 2014 4:08 AM (in response to trenholme90)I just used Rob Hecker2's example. Have a look at your inbox.
-
10. Re: My php contact form won't work. HELP!?
trenholme90 Dec 3, 2014 4:27 AM (in response to trenholme90)I tried Rob's example and it did successfully sent the information but I didn't get an email so I don't know where it went.
-
11. Re: My php contact form won't work. HELP!?
trenholme90 Dec 3, 2014 4:34 AM (in response to trenholme90)I tried the contact form on the actual website and when i pressed send, the page just went white with only the url showing.Does this mean there is something wrong with my 'action' tag in the form? The form is linked to itself.
-
12. Re: My php contact form won't work. HELP!?
trenholme90 Dec 3, 2014 6:09 AM (in response to trenholme90)Ive fixed it! I needed to update the file on the remote server so now Rob's example works. Thanks guys, appreciate the help.



