Page 1 of 1
Select file and send it by mail
Posted: Sat Jan 20, 2018 5:37 am
by eayvl
Hi, when a record is added, an email arrives but I need to attach the selected file; If the mail arrives but not the selected file.
Have a table "PRESTAMO" with 5 fields:
Fields (id, concepto, file_1, date, time)
// Email Sending event
function Email_Sending(&$Email, &$Args) {
//var_dump($Email); var_dump($Args); exit();
$Email->Recipient = "prueba@hotmail.com";
$Email->Subject = "último archivo";
$Email->Format = "HTML";
$Email->Charset = "ISO-8859-1";
$Email->AddAttachment($Args["rsnew"]["file_1"]);
return TRUE;
}
Thank you very much for your ideas.
Re: Select file and send it by mail
Posted: Sat Jan 20, 2018 12:12 pm
by arbei
Are the field "file_1" is the file name field and you are uploading files to the folder?
if so, you may need to provide the correct file path to the AddAttachment() function.
Re: Select file and send it by mail
Posted: Sat May 12, 2018 12:59 am
by eayvl
Hi,
Yes, I am selected the file and upload it to the folder.
$sAFileName = 'uploadpath/' . $rsnew['file_1'];
$Email->AttachmentFileName = $sAFileName;
The folder that I have configured in (General Options / Upload folder is "upload/") to save the files.
My field is = carpeta_red_file
But when I receive the mail the file does not arrive. Why?
My code:
if ($FILES["x_carpeta_red_file"]["size"] > 0) {
$attach_file = "upload/" . $FILES["x_carpeta_red_file"]["name"];
move_uploaded_file($_FILES['x_carpeta_red_file']['tmp_name'], $attach_file);
$mail->AddAttachment($attach_file);
I think the code is correct but I'm not sure I work with this version, v2017.0.7.
Thanks for the help.
Re: Select file and send it by mail
Posted: Tue May 15, 2018 12:17 pm
by mobhar
Remove this code:
move_uploaded_file($_FILES['x_carpeta_red_file']['tmp_name'], $attach_file);
Re: Select file and send it by mail
Posted: Wed May 16, 2018 1:30 am
by eayvl
The file is saved correctly in the following path, but it is not attached to the mail,
C:\xampp\htdocs\project\upload
if ($_FILES["x_carpeta_red_bitacora_file"]["size"] > 0) {
$attach_file = "upload/" . $_FILES["x_carpeta_red_bitacora_file"]["name"];
$mail->AddAttachment($attach_file);
}
Re: Select file and send it by mail
Posted: Wed May 16, 2018 12:05 pm
by mobhar
Just enabled Debug mode from "Tools" -> "Advanced Settings", and then regenerate ewcfg*.php file, try again, and see whether any error message displayed.
Re: Select file and send it by mail
Posted: Thu May 17, 2018 12:29 am
by eayvl
There are no mistakes, can you please try my code in my machine does not work.
The mail if it arrives but no file.
Error (0):
// Email Sending event
function Email_Sending(&$Email, &$Args) {
//var_dump($Email);
//var_dump($Args);
//exit();
$Email->Recipient = "test@hotmail.com"; //$Args["rsnew"]["Email"];
$Email->Subject = "My New Subject"; // Change subject
$Email->Content .= "\nAdded by " . CurrentUserName();
$Email->Format = "html";
if ($_FILES["x_carpeta_red_bitacora_file"]["size"] > 0) {
$attach_file = "upload/" . $_FILES["x_carpeta_red_bitacora_file"]["name"];
// move_uploaded_file($_FILES['x_carpeta_red_bitacora_file']['tmp_name'], $attach_file);
$mail->AddAttachment($attach_file);
}
return TRUE;
}
Re: Select file and send it by mail
Posted: Fri May 18, 2018 12:08 am
by eayvl
Someone uses this version, v2017.0.7 and use file sending by mail?
it would be possible to share that part of attaching the file, any help is appreciated. Thanks.
Re: Select file and send it by mail
Posted: Fri May 18, 2018 12:12 am
by mobhar
Double check this code:
$mail->AddAttachment($attach_file);
It should be:
$Email->AddAttachment($attach_file);
Re: Select file and send it by mail
Posted: Fri May 18, 2018 1:53 am
by sticcino
are you specifying the extension.
hard code the full path and file name as a test.
Re: Select file and send it by mail
Posted: Fri May 18, 2018 8:03 am
by eayvl
It is corrected but it still does not work:
mobhar wrote:
It should be:
$Email->AddAttachment($attach_file);
try with this code but the added file does not arrive either:
$Email->AttachmentFileName = "C:\xampp\htdocs\project\upload\employees.pdf";
$Email->AddAttachment ($attachmentfile);
I can not make it work...
Re: Select file and send it by mail
Posted: Fri May 18, 2018 11:47 am
by mobhar
eayvl wrote:
$Email->AttachmentFileName = "C:\xampp\htdocs\project\upload\employees.pdf";
$Email->AddAttachment ($attachmentfile);
That code will never work, since there is no "AttachmentFileName" property that belongs to the Email object.
Your attachment path file is a Windows directory based. You should use the path as a web based path, for example:
$attachmentfile = "upload/employees.pdf"; // adjust the path to yours; the path is relative to application root
$Email->AddAttachment ($attachmentfile);
Re: Select file and send it by mail
Posted: Fri May 18, 2018 11:29 pm
by eayvl
Yes, it works:
$attachmentfile = "upload/employees.pdf"; // adjust the path to yours; the path is relative to application root
$Email->AddAttachment ($attachmentfile);
It does not work:
$attachmentfile = "upload/" . $_FILES["x_carpeta_red_bitacora_file"]["name"];
$Email->AddAttachment ($attachmentfile);
Thanks.
Re: Select file and send it by mail
Posted: Sat May 19, 2018 12:10 am
by eayvl
Re: Select file and send it by mail
Posted: Wed May 23, 2018 11:40 am
by mobhar
Try to expose the Field's property by using var_dump() in "Row_Rendered" server event if you want to know/get the uploaded file name, for example:
var_dump($this->YourFieldName); // <-- adjust "YourFieldName" to your actual field name
Re: Select file and send it by mail
Posted: Sun Jun 03, 2018 8:10 pm
by vuongduongquoc
I use this code to send attachment, but in case i update the attachment, it will email the old file instead of new file.
example: First i upload a file name: picture.jpg
Next: i update the picture by upload the same file name: picture.jpg
in database before i update, the file name in field attachment is: picture.jpg
when i update the file name is picture(1).jpg because the upload file has same file name.
The attachment in email is: picture.jpg, it doens't email the picture(1).jpg.
Please help
function Email_Sending(&$Email, &$Args) {
$mailto= $this->maillinglist->CurrentValue;
$sAFileName = $this->attachment->UploadPath."/" . $this->attachment->Upload->DbValue ;
if (!ew_Empty($this->attachment->CurrentValue)){
$sAFileName = $this->attachment->UploadPath."/" . $this->attachment->CurrentValue ;
}
$Email->Recipient = $mailto;//$Args["rsnew"]["Email"];
$Email->Subject = "New PO Added"; // Change subject
$Email->Content .= "\nAdded ".$sAFileName ." By User: ". CurrentUserName() ." Update sent to: " .$mailto;
$Email->Format = "html";
$Email->AddAttachment ($sAFileName);
return TRUE;
}
Re: Select file and send it by mail
Posted: Sun Jun 03, 2018 8:21 pm
by vuongduongquoc
Solved.
I changed to: $Args["rsnew"]["attachment"]
function Email_Sending(&$Email, &$Args) {
$mailto= $this->maillinglist->CurrentValue;
$sAFileName = $this->attachment->UploadPath."/" . $Args["rsnew"]["attachment"] ;
if (!ew_Empty($this->attachment->CurrentValue)){
$sAFileName = $this->attachment->UploadPath."/" . $this->attachment->CurrentValue ;
}
$Email->Recipient = $mailto;//$Args["rsnew"]["Email"];
$Email->Subject = "New PO Added"; // Change subject
$Email->Content .= "\nAdded ".$sAFileName ." By User: ". CurrentUserName() ." Update sent to: " .$mailto;
$Email->Format = "html";
$Email->AddAttachment ($sAFileName);
return TRUE;
}