Email was sent with empty file attached ?

the mail() function

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Sun Nov 10, 2013 12:34 am

Email was sent with empty file attached ?

Postby sxmfranck » Sun Nov 10, 2013 12:40 am

Hello fellow php dev,

I have a PhP code to send email with attached files if any.

If files are attached, email is sent correctly, content + files

If no file is attached an empty file named Part 1.2" 0 kbytes is attached that creates warning by firewalls that consider it as a suspect file.

The code is below, how can I avoid that empty file to be sent ???
Thank you for your kind help

$headers .= "Reply-To:\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$headers .= "This is a multi-part message in MIME format.\n";

$headers .= "--".$strSid."\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "Content-Transfer-Encoding: 7bit\n\n";
$headers .= $message."\n\n";

//*** Attachment ***//
$strFilesName = $attachments[$i];
$strContent = chunk_split(base64_encode(file_get_contents("up_files/".$strFilesName)));
$headers .= "--".$strSid."\n";
$headers .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$headers .= "Content-Transfer-Encoding: base64\n";
$headers .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$headers .= $strContent."\n\n";

if(mail($to, $subject,null, $headers)){
echo "[message] Mail has been sent! [/message]";

Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest