Code: Select all
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','FName');
pt_register('POST','LName');
pt_register('POST','Email');
pt_register('POST','Telephone');
pt_register('POST','FloorPlan');
pt_register('POST','MoveIn');
pt_register('POST','Comments');
$Comments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $Comments);if($FName=="" || $LName=="" || $Email=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$FullName = $FName . ' ' . $LName;
$filepath = 'csv/' . strip_tags ( strtolower( str_replace( " ", "", $FullName ) ) ) . '.csv';
$handle = fopen($filepath, 'w') or die('Cannot open file: '.$filepath); //implicitly creates file
$make=fopen($filepath,"a");
$to_put="";
$to_put .= $FName.",".$LName.",".$Email.",".$Telephone.",".$FloorPlan.",".$MoveIn.",".$Message."
";
fwrite($make,$to_put);
$message="Name: ".$FName." ".$LName."
Email: ".$Email."
Telephone: ".$Telephone."
What is your desired floor plan? ".$FloorPlan."
What is your desired move-in date? ".$MoveIn."
Comments: ".$Comments."
";
$message = stripslashes($message);
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->From = $Email;
$mail->FromName = $FullName;
$mail->AddAddress('jlknauff@designedbyjk.com'); // Add a recipient
$mail->WordWrap = 80; // Set word wrap to 50 characters
$mail->AddAttachment( $filepath ); // Add attachments
$mail->Subject = 'Website Contact';
$mail->Body = $message;
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo '';
?><?php
}
?>