A
A
Alexander Karpov2016-04-22 13:07:10
PHP
Alexander Karpov, 2016-04-22 13:07:10

How to send xml string to mail as file.xml file (PHP)?

The problem is the following:
There is a string value, for example

$xml ='<?xml version="1.0" encoding="WINDOWS-1251" ?>';
$xml .='<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">';
$xml .='<xsl:template match="/">';
#$xml .= и так далее....

I want to send it to the mail so that it is an attached file.xml file, preferably without creating an intermediate file on the server. Tell me please.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Karpov, 2016-04-23
@Inkognitoss

In general, it seemed to me that everyone fundamentally misunderstood my question, although Dastan's answer is warmer.
The answer will be
: we already have a line with XML, it remains only to attach it to the letter as an attachment, which was the question. You can do this for example like this:

$HTML = '<b>Текст<b>';
       //$Наш кусок кода из вопроса
        $xml ='<?xml version="1.0" encoding="WINDOWS-1251" ?>';
        $xml .='<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">';
        $xml .='<xsl:template match="/">';
      #$xml .= и так далее.... Или же иной XML формирующий процесс.


        $filename = 'file.xml'; //Такое имя файла увидит пользователь при получении.
        $subject = 'Ваш отчет, cударъ!';

        $boundary = "--".md5(uniqid(time())); //Разделитель, который нужно будет использовать чтобы разделять разные типы контента в сообщении

        //Напишем в хидере, что наше сообщение multipart (мол разный контент там будет)
        $headers = "MIME-Version: 1.0;\r\n";
        $headers .="Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";

         //Наш текст сообщения будет в перовой части сообщения в формате Html (не забываем про разделитель)
        $part1 = "--$boundary\r\n";
        $part1 .= "Content-Type: text/html; charset=windows-1251\r\n";
        $part1 .= "Content-Transfer-Encoding: base64\r\n";
        $part1 .= "\r\n";
        $part1 .= chunk_split(base64_encode(iconv("utf8", "windows-1251", $HTML))); //контент кодируется в base64, о чем мы писали в Content-Transfer-Encoding, а также мы еще перед этим нашему сообщению сменили кодировку на windows-1251

        //И самое интересное, мы ставим разделитель и помещаем контент, содержащий вложение, а также указываем имя вложения. А дальше всё как с обычным текстом, разница тут только в том, что такой контент не будет так просто отображен в почтовой программе, а отобразится как вложение, и чтобы его просмотреть, придется отдельно загрузить файл.
        $part2 = "\r\n--$boundary\r\n";
        $part2 .= "Content-Type: application/octet-stream; name=\"$filename\"\r\n";
        $part2 .= "Content-Transfer-Encoding: base64\r\n";
        $part2 .= "Content-Disposition: attachment; filename=\"$filename\"\r\n";
        $part2 .= "\r\n";
        $part2 .= chunk_split(base64_encode(iconv("utf8", "windows-1251", $xml)));
        $part2 .= "\r\n--$boundary--\r\n";

        //После всего этого мы можем отправить всё это на почту обычной функцией mail (php)
        $message = $part1.$part2

        mail(''[email protected]",$subject, $message ,$headers);

Everything should work out. If someone has comments on their own decision, then I ask. I always rejoice when they point out mistakes, especially if they argue.

D
Dastan, 2016-04-22
@dastiw1

Try this

$mail->AddStringAttachment($xml, "attachment.xml",'base64','application/xml');

M
Mikhail Goryachkin, 2015-04-22
@abaddon65

See the page code, everything is there:
Here are the names of the two main functions that are responsible for the menu:

function H8SideMenu(){
//Коде
}
function H8SideMenuItem(_id){
//коде
}

See them all written there.

D
Dima Pautov, 2015-04-22
@bootd

getbootstrap.com/javascript/#affix - does the same. With proper knowledge of css, you can also increase the points!
And now you answer, what is the music in the video?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question