Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Email was sent with empty file attached ?

the mail() function

Moderators: macek, egami, gesf

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: test@test.com\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 ***//
if(count($attachments)>0)
{
for($i=0;$i<count($attachments);$i++){
$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]";
sxmfranck
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sun Nov 10, 2013 12:34 am

Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron