On my local when I use the wp_mail() with attached files it works, but when I’m on prod it doesn’t.
The file I receive in the email is a .dat file. I read that it’s because there is a transmission problem.
Anyone has an idea ?
function sendEmail() {
$email = $_POST['email'];
$fileName = $_FILES['cv']['tmp_name'];
if (!empty($_POST['subject'])) {
$subject = '[C.V] ' . $_POST['subject'];
} else {
$subject = '[C.V]';
}
$header = [
'Reply-To' => $email . ' <' . $email . '>',
'From: ' . $email . ' <' . $email . '>',
];
$message = 'My message';
add_filter( 'wp_mail_content_type', 'set_content_type' );
if (wp_mail('myemail@email.com', $subject, $message, $header, $fileName)) {
return true;
} else {
return false;
}
}
EDIT
Here are the .dat file 68 first lines
%PDF-1.5
%âãÃÃ
12 0 obj
<<
/Linearized 1
/L 227667
/H [ 1346 222 ]
/O 14
/E 189602
/N 2
/T 227300
>>
endobj
xref
12 41
0000000017 00000 n
0000001289 00000 n
0000001568 00000 n
0000002081 00000 n
0000002218 00000 n
0000012212 00000 n
0000012252 00000 n
0000014915 00000 n
0000025948 00000 n
0000035396 00000 n
0000046815 00000 n
0000056000 00000 n
0000066681 00000 n
0000077517 00000 n
0000086394 00000 n
0000095281 00000 n
0000096108 00000 n
0000096943 00000 n
0000097770 00000 n
0000098470 00000 n
0000098763 00000 n
0000124547 00000 n
0000124713 00000 n
0000124743 00000 n
0000124951 00000 n
0000125033 00000 n
0000125341 00000 n
0000125439 00000 n
0000138448 00000 n
0000138772 00000 n
0000139520 00000 n
0000139807 00000 n
0000169417 00000 n
0000169578 00000 n
0000169608 00000 n
0000169847 00000 n
0000170149 00000 n
0000170254 00000 n
0000184698 00000 n
0000185046 00000 n
0000001346 00000 n
trailer
<<
/Size 53
/Prev 227289
/Info 11 0 R
/Root 13 0 R
/ID [<99f020cdcb4e3a58ad9fef46b6a7a7cd><99f020cdcb4e3a58ad9fef46b6a7a7cd>]
>>
startxref
0
%%EOF
I would move your uploaded file to somewhere in your wp-content and try that directory. It is probably a permission restriction since you are trying to read a file right from the tmp directory. Use move_uploaded_file to move it, and try it with the new location.