Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10310
  • Last Modified:

PHPMailer Attachments

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
noobe1
Asked:
noobe1
  • 2
1 Solution
 
waygoodCommented:
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
 
nizsmoDeveloperCommented:
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
 
noobe1Author Commented:
waygood,
I changed the line as you suggested but still not receiving the attachment.
0
 
nizsmoDeveloperCommented:
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now