email attachments - PHPMailer - How do I unlink files in temp dir.? -
i looping through files array shown in middle chunk of code, rest of code better context.
$email = new phpmailer(); $email->from = 'john@example.com'; $email->fromname = 'john doe'; $email->subject = $name_talent; $body = '<strong>address</strong> : ' .$address_talent.'<br><br>'; if ($_files) { foreach ($_files $file => $array) { $tmp_path = $_files[$file]['tmp_name']; $tmp_name = basename($_files[$file]['name']); $email->addattachment($tmp_path, $tmp_name); } } $email->body = $body; $email->ishtml(true); $email->addaddress( '#####@gmail.com' ); $email->send();
this sends attachments values in $body well. now, unlink files either after mail sent or attachments successful. inspired from answer, if below, no files attached , variables set $body eg. $address_talent
do not appear in email.
if ($_files) { foreach ($_files $file => $array) { $tmp_path = $_files[$file]['tmp_name']; $tmp_name = basename($_files[$file]['name']); if($email->addattachment($tmp_path, $tmp_name)){ unlink("$tmp_path"); } } }
Comments
Post a Comment