user1919715
user1919715

Reputation: 41

phpmailer sends email but does not include attachment

I have the following code to send an email via phpmailer, it works fine if I don't include the AddAttachment line so know that all other constants and variables translate OK.

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = EW_SMTP_SERVER;
$mail->SMTPAuth = TRUE;
$mail->Username = EW_SMTP_SERVER_USERNAME;
$mail->Password = EW_SMTP_SERVER_PASSWORD;
$mail->From = EW_SENDER_EMAIL;
$mail->FromName = EW_SENDER_EMAIL;
$mail->Subject = $mail_subject;
$mail->Body = $mail_message;
$mail->WordWrap = 50;
$mail->AddAttachment($mail_attachment);
$mail->AddAddress("[email protected]");
$mail->Send();

If I include the attachment line then the email is sent without the attachment and does not give any error message.

If I echo $mail_attachment it gives me 'leaflets/Booklet.pdf', 'leaflets/timetable-12.pdf'

My script runs in a folder called 'iytinfo' and the 'leaflets' folder is inside this one. The 2 files definately exist in the 'leaflets' folder - have I specified the path incorrectly or is there something else I am missing?

Any help would be very much appreciated. Thank you.

Upvotes: 1

Views: 334

Answers (1)

crackmigg
crackmigg

Reputation: 5881

You cannot add multiple files with one call to AddAttachment. You have to make two calls like this:

// ... 
$mail->AddAttachment('leaflets/Booklet.pdf');
$mail->AddAttachment('leaflets/timetable-12.pdf');
// ...

Or you loop through an array of your file names or whatever.

Upvotes: 1

Related Questions