Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team

I need some clarity on using php without composer, for example i need to have all phpmailer files to send email with attachment to my project. I downloaed them online and want to use them on my project to send email with attachment.
The problem now if i am using c-panel as an external server, will downloaded files still worked to accomplished this?

the lib/vendor/phpmailer/phpmailer is the current directory on c-panel and its the directory currently using to use for phpmailer. Please advice if i am missing something important.

What I have tried:

<?php

        $mailto = $_POST['mail_to'];
        $mailSub = $_POST['mail_sub'];
        $mailMsg = $_POST['mail_msg'];
       require 'lib/vendor/phpmailer/phpmailer';
       $mail = new PHPMailer();
       $mail ->IsSmtp();
       $mail ->SMTPDebug = 0;
       $mail ->SMTPAuth = true;
       $mail ->SMTPSecure = 'ssl';
       $mail ->Host = "smtp.gmail.com";
       $mail ->Port = 465; // or 587
       $mail ->IsHTML(true);
       $mail ->Username = "acc.ldevera@gmail.com";
       $mail ->Password = "accountsamplepassword";
       $mail ->SetFrom("acc.sample@gmail.com");
       $mail ->Subject = $mailSub;
       $mail ->Body = $mailMsg;
       $mail ->AddAddress($mailto);
       $mail->AddAttachment('pdf_files/reservation.pdf', 'reservation.pdf');


       if(!$mail->Send())
       {
           echo "Mail Not Sent";
       }
       else
       {
           echo "Mail Sent";
       }

    ?>
Posted
Comments
Member 15627495 3-Mar-23 8:25am    
require 'lib/vendor/phpmailer/phpmailer';
// it's a path to phpmailer package.
<pre>

once you have the same 'path' to your file 'phpmailer' , all emails will be sent.
Gcobani Mkontwana 3-Mar-23 9:18am    
@Member 15627495 fully agree but i am still researching to get enough information on this topic so can fully understand it
Andre Oosthuizen 6-Mar-23 7:07am    
Do not ever hardcode your paths to any of your files, it is bound to error some or other time in it's life - https://stackoverflow.com/questions/3270403/how-to-define-path

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900