Solved

PHPMailer Attachments

Posted on 2007-11-15
4
10,245 Views
Last Modified: 2010-08-05
Hi Experts
Using the PHPMailer code below, I got the email with messages but not the attachment. Any suggestions?

Thanks
<?php
require("class.phpmailer.php");

// Instantiate your new class
$mail = new PHPMailer();

// Now you only need to add the necessary stuff
$mail->AddAddress("txyz@gmail.com", "xyz");
$mail->AddAttachment("c:/11.txt","123.txt","base64", "application/octet-stream");  //
$mail->Subject = "Here is the subject";
$mail->Body    = "This is the message body";

if(!$mail->Send())
{
   echo "There was an error sending the message";
   exit;
      } else {
echo "Message was sent successfully";  
}


?>
0
Comment
Question by:noobe1
  • 2
4 Comments
 
LVL 9

Expert Comment

by:waygood
ID: 20290517
try just adding the file without the encoding information.

$mail->AddAttachment("c:/11.txt","123.txt");  //  assuming your running this on windows and the file exists
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20291125
The command to attach a file can be placed anywhere between $mail = new PHPMailer(); and !$mail->Send(); and it's called AddAttachment($path);. This single line will add the attachment to your mail.

$path is the path of the filename. It can be a relative one (from your script, not the PHPMailer class) or a full path to the file you want to attach.
0
 

Author Comment

by:noobe1
ID: 20295208
waygood,
I changed the line as you suggested but still not receiving the attachment.
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20295648
noobe1:

I don't think you can refer to the file in terms of your drive letter (c:/...) but just to be sure, why don't you try placing the 11.txt file in the same directory as your script, and simply change your line to:

$mail->AddAttachment("11.txt","123.txt");

see if this works?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now