Srinivasan
Srinivasan

Reputation: 303

sending mail using phpmailer not working

I am trying to send a mail from php using phpmailer with a pdf attachment located on the server. My code is below. I am not sure where I am going wrong. Please help me. Thanks in advance

require_once('class.phpmailer.php');

$bodytext = "Test mail";
$email = new PHPMailer();
$email->From      = '[email protected]';
$email->FromName  = 'my name';
$email->Subject   = 'Message Subject';
$email->Body      = $bodytext;
$email->AddAddress( '[email protected]' );

$file_to_attach = 'pdffiles/test.pdf';

$email->AddAttachment( $file_to_attach , 'test.pdf' );

$email->Send();

Upvotes: 2

Views: 919

Answers (1)

Alok Bichhwe
Alok Bichhwe

Reputation: 172

I think when you are send a file you need to to give the system path not the url path Like

$bodytext = "Test mail";
$email = new PHPMailer();
$email->From      = '[email protected]';
$email->FromName  = 'my name';
$email->Subject   = 'Message Subject';
$email->Body      = $bodytext;
$email->AddAddress( '[email protected]' );

$file_to_attach = SYSTEM_PATH.'pdffiles/test.pdf';

$email->AddAttachment( $file_to_attach , 'test.pdf' );

$email->Send();

Upvotes: 1

Related Questions