Post by Joe1234 » Fri Nov 22, 2024 3:31 pm

I'm trying to attach an uploaded image to an email.
I have put in $mail->addAttachment();
The problem is, the only time the image gets attached is if I use the tmp version of the upload as:

Code: Select all

$file['tmp_name']
Which will not open up as an image once received.
And if I put the image file in the website root, then just use the file name in the addAttachment, that will attach and I can open up that image once I receive the email.

The problem is, for simplicity, I want to attach the file directly from the upload dir, but it is not working. I put in the path from the server home, and I also tried backing out of the website root to go into the storage dir like: "./extensions/storage/upload" but that didn't work.

Any ideas?
Last edited by Joe1234 on Sat Nov 23, 2024 3:17 am, edited 1 time in total.

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Fri Nov 22, 2024 7:03 pm

From memory addAttachment will need a full path. So if file.png was in the image directory you would use.

Code: Select all

$mail->addAttachment(DIR_IMAGE . 'file.png');

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Joe1234 » Fri Nov 22, 2024 7:55 pm

So the path has to be a url? So that means I can't use the upload folder?

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by paulfeakins » Fri Nov 22, 2024 8:03 pm

Joe1234 wrote:
Fri Nov 22, 2024 3:31 pm
I'm trying to attach an uploaded image to an email.
It's often better to embed images rather than attach them you know?

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by ADD Creative » Sat Nov 23, 2024 2:57 am

Joe1234 wrote:
Fri Nov 22, 2024 7:55 pm
So the path has to be a url? So that means I can't use the upload folder?
No, it has to be a path not a URL. Have you tried?

Code: Select all

$mail->addAttachment(DIR_UPLOAD . 'file.png');

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Joe1234 » Sat Nov 23, 2024 3:16 am

Figured it out. UNDERSCORES!!! Really? Why would the system be built on rejecting attachment names with underscores in them?

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by modulepoints » Sat Nov 23, 2024 2:47 pm

Joe1234 wrote:
Sat Nov 23, 2024 3:16 am
Figured it out. UNDERSCORES!!! Really? Why would the system be built on rejecting attachment names with underscores in them?
Are you means GMAIL, YAHOO, OUTLOOK, ETC. ?

Opencart Extensions || Opencart Premium Partner || OpenCart Upgrade Services, Opencart Customization Work, Opencart Website Development, Opencart Extensions related queries, support OR Please Email at: support@modulepoints.com for any kind question, support, help, etc.


User avatar
New member

Posts

Joined
Tue Jun 30, 2020 12:04 pm

Post by Joe1234 » Sun Nov 24, 2024 11:26 am

opencart. When I attach a file from the storage upload directory it works fine when the name does not contain and underscore. Once I put the underscore in the name no file gets attached. The email is going to my private server address. I've sent email attachments to this same address with underscores by regular email and the image goes through fine so I know the problem is not the receiving email client, or my email domain filtering things out.

Any idea how to fix this?

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by Joe1234 » Mon Nov 25, 2024 9:40 am

OK, I found where the underscores are being sanitized in the upload function. What I don't understand is why, especially if hyphens are being allowed through? What is the safety risk of underscores vs hyphens before I go and add the ability to let underscores through?

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Tue Nov 26, 2024 1:05 am

I can't see that underscores would be a problem for file uploads.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom
Who is online

Users browsing this forum: Bing [Bot] and 25 guests