This topic is locked
[SOLVED]

Attachment is not sent

12/23/2024 8:36:56 AM
PHPRunner General questions
J
Jan author

Hello everyone, I am trying to send an email from a table, the email is received correctly for every email address that is in the table. But the attachment in the table is not there ...
the field with the name of the attachment is a text field (varchar(150)), the file itself is saved in the subfolder "files" of the output folder.
I used the example that is on the link below :
https://xlinesoft.com/phprunner/docs/send_an_email_with_attachment.htm

I use the php code below in the event "after record added"
Any tip is welcome. Thanks for your help.


$rs = DB::Query("SELECT emaiadress FROM mytable'");
while( $data = $rs->fetchAssoc() )
{
$email=$data["emailadress"];
$from="my@email.com";
$msg=' this is a test email with a attachment';
$subject='test'];

$fileArray = my_json_decode($values["my_files"]);

$attachments = array();
foreach($fileArray as $f)
{
$attachments[] = array("path" => $f["name"]);
}

$ret=runner_mail(array('to' => $email, 'subject' => $subject,'htmlbody' => $msg, 'from'=>$from, 'attachments' => $attachments));

if(!$ret["mailed"])
echo $ret["message"];
}
C
copper21 12/23/2024

There is a syntax error that I can see. Remove the "]" from the line: $subject='test'];

It should look like: $subject='test';

That might not fix your issue of not getting attachments, but just wanted to let you know.

As for the attachment, I have code very simliar to this and it works. Is the file kept on the webserver you are using? Can you post what the field "my_files" has in it in the database? Is should look like JSON.

J
Jan author 12/23/2024

in the field "my_files" is this text:
[{"name":"files\/test_9we9w9ur.pdf","usrName":"test.pdf","size":573393,"type":"application\/pdf","searchStr":"test.pdf,!:sStrEnd"}]

"$subject='test'];" should indeed be $subject='test';, I had typed that incorrectly

C
copper21 12/23/2024

Ja,

I was able to get this to work by uploading a document into a "files" folder in the output folder.

What are your settings in the "edit" filed properties? It should be set to File/Image, and in the uplolad folder it should just say "files" without the quotes. The absolute path is not checked.

You also might want to increase your varchar to something higher than 100, depending on how may files you may upload at at time, this will probably need to be more.

Like you mentioned, it sound like you are using the built-in web server of PHPRunner. What are your SMTP settings?

J
Jan author 12/24/2024

Hi, the email is sent (but without attachment), so SMTP settings seem to be set correctly.
I increased the field length from Varchar100 to Varchar250
I also use the folder "files", see screenshot

img alt

C
cristi 12/24/2024

If you var_dump $attachments what do you see?

J
Jan author 12/24/2024

With a google account this works fine, so I need to check the smtp settings of the provider. Thanks for your help.