Created
June 23, 2020 11:58
-
-
Save kagg-design/eb0b804d8aafd451701b4bb57cf4404e to your computer and use it in GitHub Desktop.
Mail attachment missing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'init', 'att_page', PHP_INT_MAX ); | |
function att_page() { | |
if ( is_att_page() ) { | |
$attachment = null; | |
$to = 'info@kagg.eu'; | |
$subject = 'subj'; | |
$message = 'message'; | |
include_once ABSPATH . 'wp-admin/includes/file.php'; | |
// Handle attachment | |
if ( isset( $_FILES['vip-documents'] ) && ! empty( $_FILES['vip-documents'] ) ) { | |
$attachment = get_temp_dir() . $_FILES['vip-documents']['name']; | |
move_uploaded_file( $_FILES['vip-documents']['tmp_name'], $attachment ); | |
// Headers | |
$headers = [ 'MIME-Version: 1.0' ]; | |
$headers[] = 'Content-Type: text/html; charset=UTF-8'; | |
$check_send = wp_mail( $to, $subject, $message, $headers, $attachment ); | |
if ( $check_send ) { | |
header( 'Location: /thank-you/' ); | |
} else { | |
echo 'Error'; | |
} | |
} | |
// Delete uploaded file after mail has send success/failed | |
if ( $attachment ) { | |
unlink( $attachment ); | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<form action="" method="post" enctype="multipart/form-data"> | |
Select image to upload: | |
<input type="file" name="vip-documents" id="vip-documents"> | |
<input type="submit" value="Upload Image" name="submit"> | |
</form> | |
<?php | |
exit; | |
} | |
} | |
function is_att_page(): string { | |
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) { | |
return ''; | |
} | |
$uri = filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_STRING ); | |
$path = wp_parse_url( $uri, PHP_URL_PATH ); | |
if ( '/att/' === trailingslashit( $path ) ) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment