Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Boots-

macrumors regular
Original poster
Jan 27, 2009
152
0
Canada
I'm working on a website, it's not quite finished yet, but it is in the works. I'm trying to get my contact form to work. Here is the code I have:


<?php
$contact_name = $_POST['name'];
$contact_email = $_POST['email'];
$contact_subject = $_POST['subject'];
$contact_message = $_POST['message'];

if( $contact_name == true )
{
$sender = $contact_email;
$receiver = "MyEmailHere";
$client_ip = $_SERVER['REMOTE_ADDR'];
$email_body = "Name: $contact_name \nEmail: $sender \n\nSubject: $contact_subject \n\nMessage: \n\n$contact_message \n\nIP: $client_ip \n\nFlash Contact Form provided by http://www.flashmo.com";
$extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();

if( mail( $receiver, "Flash Contact Form - $contact_subject", $email_body, $extra ) )
{
echo "success=yes";
}
else
{
echo "success=no";
}
}
?>







It doesn't seem to work when I try it out, What do I have to do to make it work? (besides adding my email where it says EmailHere)
 
Short answer, your if statement. You should check that it's not empty,
PHP:
if ($contact_name != '') {
There's a number of security issues though. Your form can easily be turned into a spam machine. You must validate the data being submitted through the form, otherwise it'll be a prime candidate for email-injection attacks.

Side note; When posting code be sure to use the appropriate code tags i.e., use the PHP button around your code. This will properly format and color code the code you post like you see above.
 
What can I do to make it work, and make it not a spam machine?

Read the link I gave. You didn't say if you tried the revised if statement I suggested, and you haven't said in what way it isn't working. Are there errors, is there any output? We also don't know what your form looks like.
 
I just found out that Bravenet does not support PHP with a free account, what is a good, free webhost to use?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.