Help with Akismet (PHP5 plugin)

Hi all,

I’m trying to use the Akismet PHP5 plugin to stop spam on my website (not WordPress site) which is using a standard form.

Not sure if I’m setting this up correctly or not, can’t seem to find much if any documentation around for it, plus the authors website no longer appears to exist, only the info in Github is available. Anyways, not sure if the fields such as telephone, department, comment1 and comment2 all should go through SetCommentContent or not? Any help/advice on any of my code would be appreciated. Not sure if I’m running tests/checks on this okay as well.


<?php

require_once ('classes/Akismet.class.php');
$akismet = new Akismet( "http://localhost/akismet-form", "API key to go here");


// checks if key is valid
if($akismet->isKeyValid()) {
	// api key is okay
} else {
	echo 'Akismet key is invalid';
	die();
}


if (isset($_POST['submit'])) {


	// assign variable
	$name = $_POST['name'];
	$department = $_POST['department'];
	$url = $_POST['url'];
	$email = $_POST['email'];
	$telephone = $_POST['telephone'];
	$comment1 = $_POST['comment1'];
	$comment2 = $_POST['comment2'];

	// run variables through Akismet function
	$akismet->setCommentType("enquiry");
	$akismet->setCommentAuthor( $name );
	$akismet->setCommentAuthorURL( $url );
	$akismet->setCommentAuthorEmail( $email );

	// run everything that doesn't have a specifc class for it through CommentContent
	$akismet->setCommentContent( "$department $telephone $comment1 $comment2" );


	// spam check
	if( $akismet->isCommentSpam() )
	{
		echo 'This email contains spam!';

	}
	else
	{

		$to      = 'myemail@test.com';
		$subject = 'Akismet test';
		$message =  'All content goes in here';
		$headers = 'From: webmaster@mysite.com' . "\\r\
" .
		   'Reply-To: webmaster@mysite.com' . "\\r\
" .
		   'X-Mailer: PHP/' . phpversion();

		mail($to, $subject, $message, $headers);


		// check if email sent
		if(mail($to,$subject,$message)){
		   echo "Message Sent";
		} else {
		   echo "Message Not Sent";
		}


	}

}


?>

<!DOCTYPE html>
<html dir="ltr">
<head>
	<meta charset="UTF-8" />
	<title></title>
	<meta name="viewport" content="width=device-width, minimum-scale=1.0" />
	<meta name="description" content="" />
		<link rel="stylesheet" href="css/style.css" />
		<!--[if lt IE 9]>
			<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
		<![endif]-->
</head>
<body>

	<main role="main">

		<form action="" method="post">

			<ul>
				<li>
					<label for="name">Name</label>
					<input type="text" id="name" name="name" value="" />
				</li>
				<li>
					<label for="department">Department</label>
					<input type="text" id="department" name="department" value="" />
				</li>
				<li>
					<label for="url">URL</label>
					<input type="text" id="url" name="url" value="" />
				</li>
				<li>
					<label for="email">Email</label>
					<input type="text" id="email" name="email" value="" />
				</li>	
				<li>
					<label for="telephone">Telephone</label>
					<input type="text" id="telephone" name="telephone" value="" />
				</li>				
				<li>
					<label for="comment1">Comment 1</label>
					<textarea id="comment1" name="comment1" cols="20" rows="4"></textarea>
				</li>
				<li>
					<label for="comment2">Comment 2</label>
					<textarea id="comment2" name="comment2" cols="20" rows="4"></textarea>
				</li>
				<li>
					<input type="submit" name="submit" value="Submit" />
				</li>

		</form>
		
	</main>

</body>
</html>