I am not sure if this is a server issue as seemed to be working on my testing server but now live on the clients server this issue is arising. The email is generated from a form which includes a file upload in either word or pdf which is saved to the server and then attached to the email.

The problem is that the files are coming through in the email without any file extension by the looks of things so .doc files open as .txt files and .pdf files open as gobbledigook.

Can anyone shed any light on this (the server is on PHP 5.2.9 if this does have any impact). Not sure if code is needed but the attachment part is:

// From applications class to rename file upload
this->ext = pathinfo($file['name'], PATHINFO_EXTENSION);
$this->filename = $name.'-'.date('dmY-Hi').'-cv.'.$this->ext;
// $_POST['cv_file'] is re-populated with the new filename in the form submission page before email is sent (this is because I use the array of posted values to insert into the database rather than having to type them out over and over)
$mail->AddAttachment('files/cvs/'.$_POST['cv_file'], "CV File");
Member Avatar for diafol

I didn't quite understand the $_POST bit.
Shouldn't this->ext be $this->ext?

Anyway your uploaded filename will be something like this?

$fname = $_FILES['file']['name'];
$this->ext = pathinfo($fname, PATHINFO_EXTENSION);

//I assume you've done the if move_upload thing to get the file to its destination

$this->filename = $name.'-'.date('dmY-Hi').'-cv.'.$this->ext;
$mail->AddAttachment('files/cvs/'.$this->filename, "CV File");

In other words, I think it's the this->ext missing the $ that's caused the problem

Sorry the missing $ is just my copying and pasting (yes to move_upload etc, this is just a snippet to show the filename formatting).

The filename is all correct as the name is stored in the database correctly and the file opens in the correct software from the link in the admin area, it is just changing to being a filename without an extension when attached to the confirmation email.

I will try changing the reference to the filename in the attachment and see what happens.

Unfortunately that hasn't worked either.

Member Avatar for diafol

Have you tried hard-coding the filename (just for now) to see if it's an issue with the email code?

$mail->AddAttachment('files/cvs/a-file-that-already-exists.doc', "CV File");

That was a great idea, but still no good I am afraid (attached a .doc and it came through without an extension)

To be hoest I haven't tried any other file types and it was working on my server so I am still wondering if it is a server issue instead. I will try out a different file type and see what happens.

No good :-(

Resolved!!!!

I changed the name of the file (2nd parameter in code below) from just 'CV FIle' to the actual name of the file being attached.

$mail2->AddAttachment('files/cvs/'.$cv->filename, $cv->filename);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.