From a form, via wp_mail function, I’m trying to send an email with an attachment, without upload the file to the file manager.
I’m getting the email with an attachment. But the attachment name not correct and no file type. Please help to solving this.
This is HTML form
<form action="POST" enctype="multipart/form-data">
<table>
<input type="file" name="Attached">
<input type="Submit" name="Submit">
</table>
</form>
There is my PHP Code
if (isset($_POST['Submit'])) {
$attachments = $_FILES['Attached']['tmp_name'];
$recipients = "john@mail.com";
$SenderName = get_bloginfo('name');
$SenderEmail = "noreply@domain.com";
$body = "How are you what are you doing now. bla bla bla";
$recipients = array($to);
$headers[] = "From: $SenderName <$SenderEmail>" . "rn";
$headers[] = "Content-Type: text/html";
$subj = "This is mail subject";
$SendMail = wp_mail( $recipients, $subj, $body, $headers, $attachments );
}
Well I had to come up with workaround for this one
What I did is
1.Upload the file to the server
2.email with wp-mail
3.on successful email or not unlink the uploaded image