Skip to content

Instantly share code, notes, and snippets.

@mahfuj156
Created September 1, 2020 07:09
Show Gist options
  • Save mahfuj156/73c29511196c6317a4df1fc77062c3a7 to your computer and use it in GitHub Desktop.
Save mahfuj156/73c29511196c6317a4df1fc77062c3a7 to your computer and use it in GitHub Desktop.
Custom code for WP MAIL With Attachment
if(isset($_POST['photoupload_submit'])){
$rand = rand(0000,9999);
// Count total files
$countfiles = count($_FILES['file']['name']);
$subject = "Payment received #$orderidnumber";
$message ='<p>You have reviced payment following order Id: ' . $activation_link . '</p>';
$headers[] = 'From: INOVA <website@doamin.com>' . "\r\n";
$headers[] = "Reply-To: $useremail \r\n";
// Looping all files
for($i=0;$i<$countfiles;$i++){
$filename = $_FILES['file']['name'][$i];
// Upload file
$uploadfile = get_template_directory() .'/upload/'.$rand.$filename;
$filetempname = $_FILES['file']['tmp_name'][$i];
move_uploaded_file($filetempname, $uploadfile);
$attachment[$i] = $uploadfile;
}
$file_to_upload = ABSPATH . '/wp-content/themes/inova/upload/'.$rand.$filename;
$attachments = array( $file_to_upload);
wp_mail($administratoremail, $subject, $message, $headers, $attachment);
if(wp_mail){
echo "<h2 class='upload-photo-success-message'>Your file successfully submitted. You will receive a confirmation email soon.</h2>";
}
else{
echo "<h2>Error</h2>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment