I have this function below “sendMail”, to send emails using phpmailer class. And its working fine, Im already sending emails with sucess.
But now Im trying to add one attachment to my function, so I added this to my code:
$mail->AddAttachment(BASE.‘/’.‘images/2014/05/image4.jpg’,‘image 4’);
And Im having this error:
Could not access file: localhost/project/images/2014/05/image4.jpg
But this directory is exactly the correct directory to my image, so I dont understand why this error is happening.
Somebody there knows if Im missing something here?
My function to send email:
function sendMail($subject,$message,$emissor,$emissorName,$receptor,$receptorName, $reply = NULL, $replyName = NULL){
require_once('mail/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->IsHTML(true);
$mail->SMTPSecure = "tls";
$mail->Host = MAILHOST;
$mail->Port = MAILPORT;
$mail->Username = MAILUSER;
$mail->Password = MAILPASS;
$mail->From = utf8_decode($emissor);
$mail->FromName = utf8_decode($emissorName);
$mail->Subject = utf8_decode($subject);
$mail->Body = utf8_decode($message);
$mail->AddAddress(utf8_decode($receptor),utf8_decode($receptorName));
$mail->AddAttachment(BASE.'/'.'images/2014/05/image4.jpg','image 4');
if($reply != NULL){
$mail->AddReplyTo(utf8_decode($reply),utf8_decode($replyNome));
}
if($mail->Send()){
return true;
}
else{
return false;
}
}
And my server acess file, when I acess this url: htttp://localhost/projeto/banner-imagens/2014/05/bib_idh.jpg, I get my image!