Cape Navigators – Your Real Estate Team on Cape Cod

Cape Navigators

Your Real Estate Team on Cape Cod

Sign up below for our monthly market update and stay informed about the latest real estate trends in Cape Cod, Plymouth, and Wareham.









© Cape Navigators. All rights reserved.

// the form data and send an email with a CSV attachment
function submit_contact_form() {
if ( isset( $_POST[‘name’] ) && isset( $_POST[’email’] ) && isset( $_POST[‘neighborhood’] ) ) {
$name = sanitize_text_field( $_POST[‘name’] );
$email = sanitize_email( $_POST[’email’] );
$neighborhood = sanitize_textarea_field( $_POST[‘neighborhood’] );

// Convert the form data to a CSV file
$csv_data = array(
array( ‘Name’, ‘Email’, ‘Villages/Towns of Interest’ ),
array( $name, $email, $neighborhood ),
);
$csv_content = ”;
foreach ( $csv_data as $row ) {
$csv_content .= implode( ‘,’, $row ) . “\n”;
}

// Send the email with the CSV attachment
$to = ‘davemahler@kw.com’;
$subject = ‘New Contact Form Submission’;
$message = ‘A new contact form submission has been received. Please see the attached CSV file for details.’;
$headers = array(
‘From: ‘ . $name . ‘ <‘ . $email . ‘>’,
‘Content-Type: text/csv’,
‘Content-Disposition: attachment; filename=”contact-form.csv”‘,
);
wp_mail( $to, $subject, $message, $headers, $csv_content );
}

wp_redirect( home_url() ); // Redirect the user to the homepage after submission
exit;
}
add_action( ‘admin_post_nopriv_submit_contact_form’, ‘submit_contact_form’ );
add_action( ‘admin_post_submit_contact_form’, ‘submit_contact_form’ );
?>