PHPMailer giving rtf file .txt extension - yii

First time using PHPMailer within Yii and i've got the files to attach fine in email form using .doc, .rtf and .txt. I then tried to add the optional name to the file rather than the uploaded name and my rtf file was sent as a .txt file. Not sure why? Wondered if anyone could point me int he right direction.
$mail = new YiiMailer();
//$mail->clearLayout();//if layout is already set in config
$mail->setFrom('email#example.com', 'Me!');
$mail->setTo(Yii::app()->params['adminEmail']);
$mail->setSubject('Mail subject');
$mail->setBody('Simple message');
$mail->AddAttachment($dest . '/' . $file->tmp_name . '.' .$file->extension, $file->name);
Thanks in advance
Jonnny

Seems that if I pass all the arguments to the AddAttachment() it sends the RTF as a .doc file.
$mail->AddAttachment($dest . '/' . $file->tmp_name . '.' .$file->extension, $file->name, 'base64', $file->mime_type);
Jonnny

Related

pdf file renamed in email

I am struggling with the file name of a PDF created on the fly (FPDF 1.82) using PHPMAILER (6.3.0) under PHP 5.6.17
$pdfdoc = $pdf->Output('pdf_doc.pdf', 'S');
$mail->addStringAttachment($pdfdoc, 'pdf_doc.pdf', 'base64', 'application/pdf');
Everything works fine only the attached PDF file is renamed .$path !
The file sent is a perfectly readable non corrupted pdf file.
$doc = $pdf->Output('pdf_doc.pdf', 'F'); downloads the file with the proper name !!!
The only clue would be in the error message :
Fatal error: Uncaught exception 'PHPMailer\PHPMailer\Exception' with
message 'Could not access file: ' in ....
PHPMailer\PHPMailer\PHPMailer->addAttachment('', 'pdf_doc.pdf')
meaning that the $doc is not recognised
Well, you know everything ...Any idea of what can go wrong with this pdf title ?
Many thanks

How to access pdf file outside of public_html in joomla site?

Actually i want to edit a module to fetch PDF file outside from public_html.
I already tried to change permission of that file from which i want to fetch PDF to 777.
I am trying to fetch PDF by following codes
$baseurl = JURI::base();
$outside_baseurl = $baseurl.'../pdf/name.pdf';
Shows this error
Cannot access file!
https://mysitedomain.com/../pdf/name.pdf
It's really not safe to access a file outside the scope of your public folder in the open like that. It has the potential to open serious security holes. If you are trying to do this to modify or use the PDF file for something inside PHP, you should be able to. If you are trying to send it to a user for download or preview, you might wanna try fpassthru(). Something like the example below.
<?php
$path = 'path/to/file.pdf';
$public_name = basename($path);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $path);
header("Content-Disposition: attachment; filename=$public_name;");
header("Content-Type: $mime_type");
header('Content-Length: ' . filesize($path));
$fop = fopen($path, 'rb');
fpassthru($fop);
exit;
This should serve your purpose.

How to create and set content type in Vcard generate file in PHP

I have been working to generate vcard file in php just simple way.
my code like following :
header('Content-Type: text/x-vcard;charset=utf-8;');
header('Content-Disposition: inline; filename= "'.$file.'"');
header("Pragma: no-cache");
and generated file is something like this:
BEGIN:VCARD
FN:Elke Schöne;
ADR;INTL;HOME:;;;Leipziger Straße 3;Markranstädt;04420;
EMAIL;INTERNET:praxis.elkeschoene#t-online.de
TEL;FAX;HOME:+49 34205 83980
TEL;HOME:+49 34205 88249
URL;WORK:www.praxis-schoene.de
REV:20161207
END:VCARD
But when i open this file in Windows Contact then name "Schöne" is not encoded and display with special character, but it works fine in Thunderbird contact.
can anybody help me..
You can add the charset:
FN;CHARSET=Windows-1252:Elke Schöne
The semi colon at the end of the lines is not needed on vcard.

nodejs npm libraries to access and modify microsoft word documents

Do you know if it is possible to search specific text like "xAx" into a Microsoft Word file (.doc or .docx) hosted on a website, replace it with some other text input by the user and make the file available for download using nodejs?
Is there a npm library that can do that?
If not it is possible to manipulate a PDF file instead? Please note that I do not want to create the document but manipulate a template file in the server.
Thank you for your help.
There is project https://github.com/open-xml-templating/docxtemplater which serves for replacing {placeholders} in a .docx files.
Also supports loops and images, check out demo (examples) on http://javascript-ninja.fr/docxtemplater/v1/examples/demo.html
If odt is an option (these files are open directly by MS Word besides Open and Libre Office and can be set with extension .doc so end users do not freak out) you can use HTML52PDF.
For example something like the following code will replace a string of text by a link:
require_once 'path/to/CreateDocument.inc';
$doc = new Html52pdf\createDocument(array('template' => 'template.odt'));
$format = '.odt';//.pdf, .doc, .docx, .odt, .rtf
//replace natural text
$doc->replace(array('replace me, please' => array('value' => 'external link')), array('format' => array('','')));
$doc->render('replaced_content' . $format);

Create dummy index.html inside a new MKDR directory

I know this may be a silly question but i cant seem to find just a simple answer.
I have a php script that makes a directory for me when the user starts a new entry.
That directory holds photos for their gallery.
What i would like to do is also create One index.html file inside that new directory with a few lines of html code in it.
How do i do this?
Im guessing that the file would be made like so:
mkdir('users/'.$id.'/index.html',0755);
But how do i add the html into that index.html file?
Or do i have one file on the server and copy it over into there during the MKDIR process?
Anyways a really simple answer would be best as i am very slow in this learning thing.
Thank you
John
New edits.....
<?php
$id = 812;
mkdir('users/'.$id,0755);
chmod('users/'.$id,0777);
$fh = fopen( "users/".$id, "w+" ) or die( "Couldn't open file" );
fwrite( $fh, "<html><head /><body><h1>It Works!</h1></html>" );
fclose( $fh );
?>
Its giving me this error?
Warning: fopen(users/812) [function.fopen]: failed to open stream: Permission denied in stackoverflowtest1.php on line 9
Couldn't open file
Any ideas? I am on a wamp windows 7 server and not using ftp to edit files but just the www wamp explorer foler.
I'm not sure which language you are using so you'll either need to update your question or forgive the lack of concrete code. mkdir is for generating directories and not flat files. To do that you'll need to open then the file handle then print the HTML lines to that handle and then close it.
A file handle is a pointer to a file. It allows you to manipulate the data in that file ( i.e. read or write it ).
example code:
$fh = fopen( "path/to/file/index.html", "w+" ) or die( "Couldn't open file" );
fwrite( $fh, "<html><head /><body><h1>It Works!</h1></html>" );
fclose( $fh );
The path to the file needs a file name as a target, sorry that wasn't clear.