Solved

PHPMailer Attachments

Posted on 2007-11-15
4
10,286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

636 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