logo
down
shadow

PHP Mail with attachment - but file is empty


PHP Mail with attachment - but file is empty

By : sujit singh
Date : October 23 2020, 08:10 AM
I hope this helps you . Making a PHP script that also has a text file included as attachment. It works perfectly when I send to a GMAIL-address, but when I send to an address located at another web hoster, I can see that the file is attached, but when I open it, the file is empty (no content)... What can cause this?? This is the code I use: , If you look at a raw email:
code :
--_004_8b72e1a6b3f242208a89b3fa9240bcf3avode_
Content-Type: application/pdf; name="TA1_031_21204-2.pdf"
Content-Description: TA1_031_20181204-2.pdf
Content-Disposition: attachment; filename="TA1_031_21204-2.pdf";
    size=230847; creation-date="Mon, 10 Dec 2018 11:33:32 GMT";
    modification-date="Mon, 10 Dec 2018 09:44:35 GMT"
Content-Transfer-Encoding: base64

JVBERi0xLjUNJeLjz9MNCjI4MDYgMCBvYmoNPDwvTGluZWFyaXplZCAxL0wgMjMwODQ3L08gMjgw
OC9FIDMzOTcvTiAyOC9UIDIzMDE2NS9IIFsgNDY3IDM0NF0+Pg1lbmRvYmoNICAgICAgICAgICAg
DQoyODEyIDAgb2JqDTw8L0RlY29kZVBhcm1zPDwvQ29sdW1ucyA0L1ByZWRpY3RvciAxMj4+L0Zp
bHRlci9GbGF0ZURlY29kZS9JRFs8MDU4QTRCNjk5OEFDNzE0M0JCRUZEMDFENjJCOEE5ODg+PDZG
Q0FDM0U1RTAyOTNDNDU5QzE2MkQzMTczMjM5RTYyPl0vSW5kZXhbMjgwNiAxM10vSW5mbyAyODA1
$message .= "Content-Disposition: attachment;\r\n filename*=utf-8''" . rawurlencode($filename).$eol;
$message .= 'Content-Disposition: attachment; filename=". rawurlencode($filename).";'.$eol.$eol;


Share : facebook icon twitter icon
Some mail clients see empty CSV attachment from PHP mail() after switch from sendmail to qmail

Some mail clients see empty CSV attachment from PHP mail() after switch from sendmail to qmail


By : Jimmy Carter
Date : March 29 2020, 07:55 AM
hop of those help? I think it is a CR/LF problem, which is a known Bug in php for about three years and -as far as I know- hasn't been fixed up to now:
http://bugs.php.net/bug.php?id=15841
PHP mail() - HTML shows up as an attachment once a file attachment is added

PHP mail() - HTML shows up as an attachment once a file attachment is added


By : user2199585
Date : March 29 2020, 07:55 AM
it fixes the issue Pekka had it right - It was simple and robust to use Swiftmailer. http://swiftmailer.org
Empty File with Mail attachment - PHP

Empty File with Mail attachment - PHP


By : user3854373
Date : March 29 2020, 07:55 AM
Does that help I am using the below script to send an attachment with a mail. It sends the mail but the file attached is empty. I have gone through the script but don't seem to find where the error is coming from. , check your code
code :
$content = chunk_split(base64_encode(file_get_contents($file)));
$content = chunk_split(base64_encode(file_get_contents($file_name)));
CodeIgniter's mail library sends a mail with an empty attachment

CodeIgniter's mail library sends a mail with an empty attachment


By : Shatha_Musallam
Date : March 29 2020, 07:55 AM
around this issue I reanalyzed the mail headers & bodies and discovered a missing blank line, which is the problem:
code :
Content-Type: image/gif; name="57e30c92aaa65393755646.gif"
Content-Disposition: attachment;
Content-Transfer-Encoding: base64
R0lGODlhLAGoAPcAADwkGEAnHEMpIEQsIEQtJEgxJks1K082KVM4KVQ9KlQ8Lk85MVI9NFQ/N1JA...
Content-Type: image/gif; name="57e30c92aaa65393755646.gif"
Content-Disposition: attachment;
Content-Transfer-Encoding: base64

R0lGODlhLAGoAPcAADwkGEAnHEMpIEQsIEQtJEgxJks1K082KVM4KVQ9KlQ8Lk85MVI9NFQ/N1JA...
protected function _append_attachments(&$body, $boundary, $multipart = null)
{
    for ($i = 0, $c = count($this->_attachments); $i < $c; $i++)
    {
        if (isset($multipart) && $this->_attachments[$i]['multipart'] !== $multipart)
        {
            continue;
        }

        $name = isset($this->_attachments[$i]['name'][1])
            ? $this->_attachments[$i]['name'][1]
            : basename($this->_attachments[$i]['name'][0]);

        $body .= '--'.$boundary.$this->newline
            .'Content-Type: '.$this->_attachments[$i]['type'].'; name="'.$name.'"'.$this->newline
            .'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline
            .'Content-Transfer-Encoding: base64'.$this->newline
            .(empty($this->_attachments[$i]['cid']) ? '' : 'Content-ID: <'.$this->_attachments[$i]['cid'].'>'.$this->newline.$this->newline)
            .$this->_attachments[$i]['content'].$this->newline;
    }

    // $name won't be set if no attachments were appended,
    // and therefore a boundary wouldn't be necessary
    empty($name) OR $body .= '--'.$boundary.'--';
}
$body .= '--'.$boundary.$this->newline
                .'Content-Type: '.$this->_attachments[$i]['type'].'; name="'.$name.'"'.$this->newline
                .'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline
                .'Content-Transfer-Encoding: base64'.$this->newline
                .(empty($this->_attachments[$i]['cid']) ? $this->newline : 'Content-ID: <'.$this->_attachments[$i]['cid'].'>'.$this->newline.$this->newline)
                .$this->_attachments[$i]['content'].$this->newline;
Sending a mail with attachment in Java without needing a physical attachment file

Sending a mail with attachment in Java without needing a physical attachment file


By : Chain gate hostel
Date : March 29 2020, 07:55 AM
Related Posts Related Posts :
  • Running two PHP versions on the same server (STRETCH)
  • Checking if a file has been selected for upload
  • Model not updating laravel
  • How to add a description of words from text to an array, to an array key by passing words?
  • Nginx rewrite rule not not passing variables if "/" is at the end of the url
  • Modify decimal point and thousands separator without changing the number of decimals
  • Remove PHP errors from CLI and PHPMyAdmin
  • Yii2 rest api - Url manager add parameters
  • 1-query batch update array of users using PDO
  • Keep getting error: implode(): Invalid arguments passed when updating data
  • Laravel 5.4 - Correct Validation rule for a required parameter that can be zero
  • What does this code mean: $objPHPExcel->getActiveSheet()->toArray(null, true,true,true)
  • Data not being added to mysql table but echo's the data?
  • While fetch row in PHP
  • IP long string filter
  • How to view first image in list per user as its highlight Profile
  • Insert multiple rows from array
  • PHP : How to remove a duplicate array item ONCE
  • Print the input box text as simple text instead of html tag
  • How to read a string variable in php as $_GET or $_POST?
  • MySQL query fetch array not working
  • LogicException with message '... must return a relationship instance.'
  • PHP - create new array with only selected keys from an existing array
  • How to allow backgrounding a process to survive a session termination?
  • How to redirect to Home page (Default page) in zend framework 2?
  • I want to call a jquery variable in php syntax
  • Disabling the default /?add-to-cart= animation on buttons in Woocommerce
  • How to use query data for another sql query in yii2
  • Replace string enclosed in specified characters based on data type
  • Symfony FormType: how to get prototype in form type file
  • Handle reply messages properly after some operations in php
  • PHP Changed Domain, how to remove old Session Cookies
  • mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in php
  • Error: Call to a member function update() on array laravel
  • How to change the format of a float number?
  • run ajax requests by order
  • Wordpress Install 404 Error (Cannot view login in browser)
  • Calcinai xero-php pass config once
  • Fatal error calling to undefined function in PHP file
  • Laravel hasMany and belongsTo parameters
  • How do I call a Controller method in php Laravel?
  • How to replace "@" post tag with regex in PHP?
  • Laravel : when insert record in table. How can i add that Record in the list without querying the db
  • It is possible that I could user email address to get customer id from simPRO API?
  • PHP add and merge sql result
  • laravel ckeditor dark theme
  • Laravel belongsToMany not working
  • laravel 5.4 datatables not working jquery $ referenceError
  • Zend Form 2 multiselect field is empty after validation
  • PHP - Laravel 5 get data to html table from 3 SQL database tables with column DATA as headers
  • Can't use token authorization with Laravel Passport
  • splitting lines of dates and presenting in desired format
  • Laravel 5.2 Heroku Deployment Failed to install system packages
  • Laravel relationships - are there multiple *unnecessary* database calls?
  • htaccess rewrite rule for serving index.php from parent directory
  • PHP/MongoDB - $concat aggregation
  • Remove ajax.googleapis.com from my Wordpress site
  • Image saved always empty with Storage::put in Laravel
  • How to count and sort data in junction table
  • Get common number of values in a single array
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org