Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add file attachment in PHPMailer?

Tags:

php

phpmailer

I am using PHPMailer for mailing facility, I want add file with each mail from my server.

following is folder structure on my server.

-public-html
  - main-folder
    - files
       - a.doc
       - b.docx
    - mailer
       - mailer.php

i have tried the following line in my mailer.php file but it is not working

$mail->AddAttachment('main-folder/files/a.doc', 'pricelist.doc'); 
like image 535
mack Avatar asked Feb 02 '12 12:02

mack


People also ask

How can I send multiple emails in PHPMailer?

phpmailer. php'); $email = new PHPMailer(); $email->From = '[email protected]'; $email->FromName = 'Your Name'; $email->Subject = $subject; $email->Body = $bodytext; while (list ($key, $val) = each ($address)) { $email->AddAddress($val); } if(!$ email->send()) { echo "Mailer Error: " .

Does PHPMailer use SMTP?

PHPMailer can use a non-local mail server (SMTP) if you have authentication. Further advantages include: It can print various kinds of error messages in more than 40 languages when it fails to send an email. It has integrated SMTP protocol support and authentication over SSL and TLS.

Is PHPMailer secure?

But SPEWS can be worse than annoying: thanks to a security vulnerability in a popular web software component called PHPMailer, crooks could use your “contact us” form to take over your whole website. 24/7 threat hunting, detection, and response delivered by an expert team as a fully-managed service.


1 Answers

try this:

$mail->AddAttachment($_SERVER["DOCUMENT_ROOT"] . '/main-folder/files/a.doc', 'pricelist.doc'); 
like image 150
Miguel Borges Avatar answered Oct 23 '22 07:10

Miguel Borges