Select file and send it by mail

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
eayvl
User
Posts: 315

Select file and send it by mail

Post 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.


arbei
User
Posts: 9370

Post 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.


eayvl
User
Posts: 315

Post 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.


mobhar
User
Posts: 11709

Post by mobhar »

Remove this code:
move_uploaded_file($_FILES['x_carpeta_red_file']['tmp_name'], $attach_file);


eayvl
User
Posts: 315

Post 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);
	}

mobhar
User
Posts: 11709

Post 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.


eayvl
User
Posts: 315

Post 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;
}


eayvl
User
Posts: 315

Post 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.


mobhar
User
Posts: 11709

Post by mobhar »

Double check this code:
$mail->AddAttachment($attach_file);

It should be:
$Email->AddAttachment($attach_file);


sticcino
User
Posts: 1043

Post by sticcino »

are you specifying the extension.

hard code the full path and file name as a test.


eayvl
User
Posts: 315

Post 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...


mobhar
User
Posts: 11709

Post 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);


eayvl
User
Posts: 315

Post 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.


eayvl
User
Posts: 315

Post by eayvl »

Solved!!!!


mobhar
User
Posts: 11709

Post 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


vuongduongquoc
User
Posts: 133

Post 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;

}


vuongduongquoc
User
Posts: 133

Post 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;
}


Post Reply