SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2014
    0 Post(s)
    0 Thread(s)

    could not acess file, using phpmailer to send email with one attachment

    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){


    $mail = new PHPMailer();
    $mail->SMTPAuth = 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->AddAttachment(BASE.'/'.'images/2014/05/image4.jpg','image 4');

    if($reply != NULL){

    return true;
    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!

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    45 Post(s)
    13 Thread(s)
    Hi miOz,

    The problem is that the AddAttachment method is expecting a file path rather than a URL.

    For a URL such as http://localhost/projeto/banner-imagens/2014/05/bib_idh.jpg, the actual file path might be something like /var/www/projeto/banner-imagens/2014/05/bib_idh.jpg
    "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts