Need help with a PHP contact form!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with a PHP contact form!

Post by Celauran »

That confirms that mail() is failing. I'd open a ticket with your hosting provider.
newguy11
Forum Newbie
Posts: 14
Joined: Thu Oct 13, 2011 3:43 pm

Re: Need help with a PHP contact form!

Post by newguy11 »

Ok after i did it properly i am getting a 500 server error. It says the resource i am looking for cannot be displayed?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with a PHP contact form!

Post by Celauran »

After you did what properly? What do you mean?
newguy11
Forum Newbie
Posts: 14
Joined: Thu Oct 13, 2011 3:43 pm

Re: Need help with a PHP contact form!

Post by newguy11 »

I placed the code in the wrong place
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with a PHP contact form!

Post by Celauran »

Post the code that resulted in the 500 error?
newguy11
Forum Newbie
Posts: 14
Joined: Thu Oct 13, 2011 3:43 pm

Re: Need help with a PHP contact form!

Post by newguy11 »

Code: Select all

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: ashfordhales'; 
    $to = 'ashfordhales@gmail.com'; 
    $subject = 'Inquiry';
			
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
				
    if ($_POST['submit']) {				 
        if (mail ($to, $subject, $body, $from)) { 
	    echo '<p>Your message has been sent!</p>';
	} else { 
	    echo '<p>Something went wrong, go back and try again!</p>'; 
	} 
	$success = mail($ashfordhales@gmail.com, 'Test', 'Test Message');
var_dump($success);
    } 
?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with a PHP contact form!

Post by Celauran »

Code: Select all

$success = mail($ashfordhales@gmail.com, 'Test', 'Test Message');
This is definitely a problem. Your email address isn't a variable; it shouldn't start with $ and should be in quotes.

Let's take the form out of the equation for a minute. Create a new PHP file containing ONLY the two lines I listed earlier, and check the results of that.
newguy11
Forum Newbie
Posts: 14
Joined: Thu Oct 13, 2011 3:43 pm

Re: Need help with a PHP contact form!

Post by newguy11 »

Now it replies bool(false)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with a PHP contact form!

Post by Celauran »

If mail() is returning FALSE, open a ticket with your hosting provider.
newguy11
Forum Newbie
Posts: 14
Joined: Thu Oct 13, 2011 3:43 pm

Re: Need help with a PHP contact form!

Post by newguy11 »

Whats a ticket? and how do i do this?
newguy11
Forum Newbie
Posts: 14
Joined: Thu Oct 13, 2011 3:43 pm

Re: Need help with a PHP contact form!

Post by newguy11 »

Does anybody know how to do this?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with a PHP contact form!

Post by Celauran »

Contact your hosting provider and complain that mail() isn't working.
Post Reply