PHPMailer : Cant send attachement - file

I have a probleme with PHPMailer .
First i used it without FTP , but all email was SPAM .
So i tried to use my FTP login and now all email are not junk .
But problem ... my attachement ( .rar and . zip ) doest work .
i tried with txt files and its ok ... i'm becoming crazy
require('class.phpmailer.php');
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->SMTPDebug = 1;
$mail->IsSMTP();
$mail->Host = "r******";
$mail->Port = "465";
//usually the port for TLS is 587, for SSL is 465 and non-secure is 25
$mail->SMTPSecure = "ssl";
//TLS, SSL or delete the line
$mail->SMTPAuth = true;
$mail->Username = 's*****';
$mail->Password = '##';
$mail->From = 'sales#*****';
$mail->FromName = '****';
$mail->AddAddress("$payer_email", "$payer_business_name");
$mail->Subject = "SUBJET";
$mail->Body = " MY MESSAGE";
if( $custom == 1 )
{
$mail->AddAttachment('test.txt');
}
if( $custom == 2 )
{
$mail->AddAttachment('test2.txt');
}
$mail->Send() ;
}
}
fclose ($fp);
}
i use if and else because its a paypal button with param . ( if 1 i send this file by mail )
this is working with txt files . but not with RAR or ZIP files ... No email send
any idea ?
thanks a lot

Related

sqlserver data to excel xlsx using php ? what wrong in this code..?

<?php
$serverName = '-'; //serverName\instanceName
$connectionInfo = array( 'Database'=>'-');
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn!='') {
'Connection established.<br />';
}else{
'Connection could not be established.<br />';
die( print_r( sqlsrv_errors(), true));
}
/** Set default timezone (will throw a notice otherwise) */
date_default_timezone_set('Asia/Kolkata');
// include PHPExcel
require('../PHPExcel.php');
// create new PHPExcel object
$objPHPExcel = new PHPExcel;
// set default font
$objPHPExcel->getDefaultStyle()->getFont()->setName('Calibri');
// set default font size
$objPHPExcel->getDefaultStyle()->getFont()->setSize(10);
// create the writer
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
/**
* Define currency and number format.
*/
// currency format, € with < 0 being in red color
$currencyFormat = '#,#0.## \€;[Red]-#,#0.## \€';
// number format, with thousands separator and two decimal points.
$numberFormat = '#,#0.##;[Red]-#,#0.##';
// writer already created the first sheet for us, let's get it
$objSheet = $objPHPExcel->getActiveSheet();
// rename the sheet
$objSheet->setTitle('My sales report');
// let's bold and size the header font and write the header
// as you can see, we can specify a range of cells, like here: cells from A1 to A4
$objSheet->getStyle('A1:D1')->getFont()->setBold(true)->setSize(12);
// write header
$objSheet->getCell('A1')->setValue('Name');
$objSheet->getCell('B1')->setValue('phone No');
// we could get this data from database, but here we are writing for simplicity
$i = '2';
$que=sqlsrv_query($conn,"SELECT * FROM table");
while($row=sqlsrv_fetch_array($que)){
$name=$row['CustomerName'];
$PhoneNo=$row['CustomerPhone'];
$data[] = array(
'name'=>$name,
'empno'=>$PhoneNo
);
}
$array = stripslashes(json_encode($data));
$json = (object)json_decode($array);
foreach($json AS $datas){
$objSheet->getCell('A'.$i.'')->setValue($datas->name);
$objSheet->getCell('B'.$i.'')->setValue($datas->empno);
$i++;
}
// autosize the columns
$objSheet->getColumnDimension('A')->setAutoSize(true);
$objSheet->getColumnDimension('B')->setAutoSize(true);
//Setting the header type
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="file.xlsx"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
/* If you want to save the file on the server instead of downloading, replace the last 4 lines by
$objWriter->save('test.xlsx');
*/
?>

how to get filename by file_id in telegram

for my new bot i need to get real file name.
when i get the file_id and requesting for generate download link with "get file" commend, the file name is look like "file_370.mp3" but the real file name is:"michaeljackson.mp3".
i tried this code:
$mp3name = $result['message']['audio']['title'];
$mp3fileid = $result['message']['audio']['file_id'];
file_get_contents( $url."/sendaudio?chat_id=118718802&audio=$mp3fileid&performer=awaperformer&title=awatitle");
$bot_url = "https://api.telegram.org/bot".$botToken;
$file_path_gen_url = $bot_url."/getfile?file_id=".$mp3fileid;
// file_get_contents( $url."/sendmessage?chat_id=118718802&text=lastfileid:filegen:$file_path_gen_url");
$file_path_result = file_get_contents($file_path_gen_url);
// echo "last file id: $last_file_id <br>";
$file_path_result = json_decode($file_path_result, TRUE);
$file_path = $file_path_result['result']['file_path'];
// echo "file_path: $file_path <br>";
$file_url = "https://api.telegram.org/file/bot".$botToken."/".$file_path;
how can i get real file name?
You can't get original file name for audio object.
here avaliable attributes : https://core.telegram.org/bots/api#audio
You can get original file name for document object.

Console Output In Windows Forms Application

CASE 1
Process processo = new Process();
processo.StartInfo.CreateNoWindow = true;
processo.StartInfo.UseShellExecute = false;
processo.StartInfo.RedirectStandardOutput = true;
processo.StartInfo.FileName = "ftp";
processo.StartInfo.Arguments = "-s:comandos.cmd";
processo.Start();
processo.WaitForExit();
output = processo.StandardOutput.ReadToEnd();
CASE 2
AllocConsole();
Process processo = new Process();
processo.StartInfo.CreateNoWindow = true;
processo.StartInfo.UseShellExecute = false;
processo.StartInfo.RedirectStandardOutput = true;
processo.StartInfo.FileName = "ftp";
processo.StartInfo.Arguments = "-s:comandos.cmd";
processo.Start();
processo.WaitForExit();
output = processo.StandardOutput.ReadToEnd();
FreeConsole();
Why the ouput is not the same using the case 1 and 2 ? The Alloc and FreeConsole are functions from kernel32.dll... Im using a windows forms application.
The comandos.cmd connect to the server and use a "dir" command.
Have a way to use AllocConsole() without show the console window ?
First output is:
User xxx
archive1
archive2
cd Folder
dir
quit
Second output is:
open xxx
User xxx
331 User ok
230 Password ok
cd Folder
archive1
archive2
226 transfer complete
xxx bytes received
quit
221 GoodBye

Corona lua: How do I attach a .txt data file saved to system.DocumentsDirectory to an email?

Corona lua: How do I attach a data file that is saved to the system directory to an email? An image of the data.txt file shows up in the email pop up on an iPad after I build, but doesn't get attached although the email is sent. Images go fine. I used "text", "plain", and "text/plain" as the mime type. If you can help with this, I would greatly appreciate it!
Try this:
-----------------------------------------------------------------------------------
-- Creating the text file --
-----------------------------------------------------------------------------------
local filePath_Type = system.pathForFile( "myTextFile.txt", system.DocumentsDirectory )
local file = io.open( filePath_Type, "r" )
if file then
io.close( file )
else
--Create an empty file--
local path_Type = system.pathForFile( "myTextFile.txt", system.DocumentsDirectory )
local file = io.open( path_Type, "w+b" )
file:write("My data inside file")
io.close( file )
end
-----------------------------------------------------------------------------------
-- Now, to email this file --
-----------------------------------------------------------------------------------
function showMailPicker()
-- Create mail options --
local options =
{
to = { "me#me.com",},
subject = "Subject Text",
body = "Email Body",
attachment =
{
{ baseDir=system.DocumentsDirectory, filename="myTextFile.txt", type="text" },
},
}
-- Send mail --
native.showPopup("mail", options)
end
submitButton = display.newImageRect("myButton.png",100,40)
submitButton.x = 160
submitButton.y = 240
submitButton:addEventListener("tap",showMailPicker)
Keep Coding.............. :)

Emails are going in spam in cake php

Here are my code:-
//Sending mail
if ($this->Session->read('Enrollment.personalinfo_language') == 'English') {
$language = "english";
$subject = "Thank you for submitting your enrollment request to Apna Energy.";
} else {
$language = "spanish";
$subject = "Gracias por enviar su solicitud de inscripci?n a Apna Energy.";
}
$details = $this->Session->read('Enrollment');
$details['plan_name'] = $product['Product']['name'];
$details['rate'] = $plan_rate;
$details['term'] = $product['Term']['term'];
$this->Email->sendAs = 'html';
$this->Email->from = 'Apna Energy <contact#apnaenergy.com>';
$this->Email->to = $this->Session->read('Enrollment.personalinfo_first_name') . ' ' . $this->Session->read('Enrollment.personalinfo_last_name') . '<' . $this->Session->read('Enrollment.personalinfo_email') . '>';
$this->Email->bcc = array('my#mail.com');
$this->Email->subject = $subject;
$this->set('details', $details);
if ($this->Session->read('Enrollment.personalinfo_language') == 'English') {
$template = "enrollment_confirmation";
} else {
$template = "enrollment_confirmation";
}
$this->Email->template = $template;
$this->Email->send();
My problem is if customer fill form they are receiving mail in his/her spam folder.. customer's mail id in "to".. and my mail id in "BCC" for me mail are coming fine in my inbox folder..
I followed two URL but they didn't work out for me..
Cakephp emails going to spam
How do you make sure email you send programmatically is not automatically marked as spam?
Guide me in right direction..
Thanks!!
by using SMTP
with normal PHP your server must be configured properly which is not easy to do as a beginner (MX records need to match the servers ip etc).
So just always stick to SMTP as mailing gateway and you will be fine.
PS: I don't think it has anything to do with your code in general, although it is not very beautiful. for instance: you should cast the array you read from the session to avoid notices thrown:
$details = (array)$this->Session->read('Enrollment');

Resources