Link to home
Start Free TrialLog in
Avatar of noobe1
noobe1

asked on

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";  
}


?>
Avatar of waygood
waygood

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
Avatar of Joe Wu
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.
Avatar of noobe1

ASKER

waygood,
I changed the line as you suggested but still not receiving the attachment.
ASKER CERTIFIED SOLUTION
Avatar of Joe Wu
Joe Wu
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial