Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHPMailer Attachments

Posted on 2007-11-15
4
Medium Priority
?
10,297 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 1500 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

715 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