0

I got little about error syntax error when I am using the PHPMailer library. I want to define my

  • email address
  • name
  • password

are constant. but when I am using the defined function. it gives me an error. I check out everything. my name email id and password are correct. when I simply define these variable everything are working well.

This is my code

<?php 

require '../phpmailer/PHPMailerAutoload.php';
require '../phpmailer/class.phpmailer.php';
require '../phpmailer/class.smtp.php';
require '../phpmailer/class.phpmaileroauth.php';

 

    class mail {
        private define("FROM", "3mrwhy@gmail.com");    
        private define("NAME", "MR WHY");
        private define("PASSWORD", "XXXXXXX");
        
        function verfication($email, $name, $subject, $body) {
    
            $mail = new PHPMailer(true);
            
            // Smtp Setting
            $mail->IsSMTP();
            $mail->Host = 'smtp.gmail.com ';
            $mail->Port = '465';
            $mail->SMTPAuth = true; 
            $mail->Username = FROM;
            $mail->Password = PASSWORD;
            $mail->SMTPSecure = 'ssl';
            $mail->From = FROM;
            $mail->FromName = NAME;
            
            // message setting
            $mail->AddAddress($email, $name);
            $mail->WordWrap = 50;
            $mail->IsHTML(true);
            $mail->Subject = $subject;
            $mail->Body = $body;
            $mail->AltBody = '';
            $result = $mail->Send();
    
            if($result['code'] == '400') {
                echo "Message is not send";
            }
            if($result) {
                echo "Email sent";
            } else {
                echo "something wrong". $mail->errorinfo;
            }   
        }
     }
    
    
    $obj = new mail();
    $obj->verfication("abheykumar7033@gmail.com", "Sudhir kumar", "Congrats", "You have created verification mail");
    ?>
Rabby
  • 322
  • 4
  • 15
  • Main point is *Finally, note that const can also be used within a class or interface to define a class constant or interface constant. define cannot be used for this purpose:* – Nigel Ren Oct 10 '20 at 07:48
  • https://www.php.net/manual/en/language.oop5.constants.php – Barmar Oct 10 '20 at 07:49

0 Answers0