Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Adding Attachment to Mail

Quote Reply
Adding Attachment to Mail
Hi,

I've written a small script that's an extension to links, and I want to attach a jpeg image to it 1/2 way through the email message body.

I'm just fiddling with the mail functions, but am getting internal server errors every time I try to include an attachment into an object with this piece of code:

$mail->attach (
type => 'text/plain',
encoding => '-guess',
body_path => '/path/to/file',
filename => 'test.txt'
);

I'm not 100% sure on what to do here, can anyone help me out?

Cheers,
R.


Quote Reply
Re: Adding Attachment to Mail In reply to
Hi,

Where are you adding this?

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Adding Attachment to Mail In reply to
Hi Alex,

I've written a small script that works like the recommend_it script, but I also want it to attach "X.jpg" that's in a particular dir when it sends. (The image it's sending will always be in the same directory.)

Cheers,
R.


Quote Reply
Re: Adding Attachment to Mail In reply to
Hi,

Hmm, the code looks ok, what does the error say in your error log? Also, it might help if you can post a URL to the full script.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Adding Attachment to Mail In reply to
Hi Alex,

"No message head was specified" is what I'm getting by the error log - but I'm not sure how to fix that? Do I have to use GT::Mail::Parts and specify a header part? Below is the error, and after that I've posted what I've got in my script at that section. (It's on a local network so I can't give you a URL to it.)

At this stage I'm just testing it with text/plain and sending a text file, but I want to send a jpeg in the end.

GT::Mail (14165): No message head was specified at /path/to/myscript.cgi line 95.

[Tue Aug 28 09:27:09 2001] [error] [client 192.168.1.224] Premature end of script headers: /path/to/myscript.cgi

---------------

# Parsing and sending

my $mail = new GT::Mail (debug => 1);

# Add an attachment to it

$mail->attach (
type => 'text/plain',
encoding => '-guess',
body_path => '/path/to',
filename => 'test.txt'
);

$mail->send(
to => $CFG->{db_admin_email},
from => $CFG->{db_admin_email} || '',
subject => "An Email 4 U!",
msg => "Hello World" || '',
smtp => $CFG->{db_smtp_server},
sendmail => $CFG->{db_mail_path},
debug => $Links::DEBUG
) or die "Error mailing Message.\n\n";


Cheers,
R.

Quote Reply
Re: Adding Attachment to Mail In reply to
Hi,

The problem is the header information needs to be specified before you add any attachments. You can do that by passing what you passed into send() to new().

Cheers,

Scott

Quote Reply
Re: Adding Attachment to Mail In reply to
Cheers Scott!

That worked a treat.

Regan.