I have one problem with my attachments in mail() PHP function. I have a simple form, once I wrote a mail.php file in my theme location on Wordpress. Now I want to add two attachments to the form.
$confirmationcontent="
<style type='text/css'>
body {
font-family: 'Arial';
color: #192933;
}
</style>
<body>
<center>
\n
<br>
<br>
<br>
<img width='50px' height='auto' src='https://example.com/wp-content/uploads/2021/05/success.png' alt='logo' />
\n
<h1>Thank you for message.</h1>
<br>
<br>
<img width='300px' src='https://example.com/wp-content/uploads/2021/05/logo.png' alt='logo' />
\n
\n
<br>
<center>
</body>
\n";
$email_2 = $_POST['email'];
$headers_2 = 'From: info@example.com' . "\r\n" ;
$headers_2 .='X-Mailer: PHP/' . phpversion();
$headers_2 .= "MIME-Version: 1.0\r\n";
$headers_2 .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers_2 .= "Content-Transfer-Encodin: 8bitr\n";
$mail_attachment = array(WP_CONTENT_DIR . '/uploads/2022/01/7883dhasdf362b.pdf');
$confirmation = "Confirmation";
$recipient_2 = $email_2;
mail($email_2, $confirmation, $confirmationcontent, $headers_2) or die("Error!");
?>
I tried to do like here for only mail() without any libraries: Send attachments with php mail
I did the same as in those replies, but I only had a blank attachment.
This was my paths:
$fileatt = "/wp-content/themes/mytheme/75sdQQds7ccds2.pdf"; //file location
$fileatttype = "application/pdf";
$fileattname = "newname.pdf";
What's the easiest way to do it? I'd rather not rewrite it in a different way. The files required for the attachment will be in wp-content/themes/mytheme or in uploads.
I also saw wp_mail() which has parameters with the ability to add attachments in the array. But how do I get wp_mail() to run in file mail.php in theme location?
I am asking for help, because I have been working on it for a long time.
Thanks