Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.
Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin. Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

PHPmailer bo'yicha muommo

+1 ovoz
79 marta ko‘rilgan
so‘radi 27 dekabr, 18 parmonov98 (1,684 bal)

PHPmail gitdan olingan, integratsiya bo'lgan classga extend qilingan. xabar jo'natishda. en uz tillarda muommosiz ketyapoti lekin RU tilida xabarlar abracadabra bo'lyapti. izladim: encoding va charset ni o'zgartirib ko'ryapman, lkekin ishlamayapti. 

nima qilish mumkin?

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;


// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
class email extends myhash{
 public $mymail;
 static public $i = 0;
 function __construct(string $lang = ''){
  $this->lang = $lang;
  
  if(self::$i == 0){
   require 'src/Exception.php';
   require 'src/PHPMailer.php';
   require 'src/SMTP.php';
   self::$i =+ 1;
  }
  
  
  $this->mymail = new PHPMailer(true);                              // Passing `true` enables exceptions
 
  $this->mymail->SMTPDebug = SMTP_DEBUG;                                 // Enable verbose debug output
  $this->mymail->charSet = 'UTF-8'; 
  $this->mymail->addCustomHeader('MIME-Version: 1.0');
  $this->mymail->addCustomHeader('Content-Type: text/html; charset=utf-8');
  $this->mymail->isSMTP();                                      // Set mailer to use SMTP
  $this->mymail->Host = SMTP_HOST;  // Specify main and backup SMTP servers
  $this->mymail->SMTPAuth = true;                               // Enable SMTP authentication
  $this->mymail->Password = SMTP_PASS_UZ;
  
  switch($this->lang){
   case 'en':
    $this->mymail->Username = SMTP_USER_EN;                 // SMTP username
    break;
   case 'ru':
    $this->mymail->Username = SMTP_USER_RU;                 // SMTP username
    break;
   case 'uz':
    $this->mymail->Username = SMTP_USER_UZ;                 // SMTP username
    break;
   default:
    $this->mymail->Password = SMTP_PASS;                           // SMTP password
    $this->mymail->Username = SMTP_USER;                 // SMTP username
   
  }
  
  #print_r($this);
  
  $this->mymail->SMTPSecure = SMTP_SECURE;                            // Enable TLS encryption, `ssl` also accepted
  $this->mymail->Port = SMTP_PORT;                                    // TCP port to connect to

  
 }
 

  
  
  // setting recipient and sender name
  function setRecipient($from, $to){
   //Recipients
   $this->mymail->addCustomHeader('MIME-Version: 1.0');
   $this->mymail->addCustomHeader('Content-Type: text/html; charset=utf-8');
   $this->mymail->setFrom($from['name'], $from['title']);
   $this->mymail->addAddress($to['name'], $to['title']);     // Add a recipient
   $this->mymail->addReplyTo($from['name'], $from['info']);

  }
  // setting content of mail message
  function formMessage($data, boolean $type = null){
   //Content
   #print_r($this);
   if($type === true)
    $this->email->isHTML(true);                                  // Set email format to HTML
   
   
   $this->mymail->Subject = $data['subject'];
   
   $this->mymail->Body .= $data['MESSAGE_BODY'][1];
   $this->mymail->Body    .= $data['MESSAGE_BODY_LINK'];
   $this->mymail->Body .= $data['MESSAGE_BODY'][2];
   $this->mymail->Body .= $data['MESSAGE_FOOTER'];
   $this->mymail->AltBody = $data['MESSAGE_BODY'][2];
   
   #print_r($this);
  }
  
  // sending message to given mail message
  function sendMessage(){
   
   
   try{
    #print_r($this);
    $this->mymail->send();
    #print_r($this);
    #echo 'Message has been sent';
    print_r($this->mymail);
    die;
    return true;
   } catch (Exception $e) {
    
    if(!$this->mymail->ErrorInfo){
     echo 'Message could not be sent. Mailer Error: ', $this->mymail->ErrorInfo;
    }else{
     echo 'Everything is okay!but Something went wrong!';
    }
    
   }

  }
  
  
 
}

bitta shubha qilayotgan joyim bu classdan asosiy controller obyekt hosil qilib kichkina controllerlarga uzatadi. shu kodda nimadir kammi? 

1 ta javob

+1 ovoz
javob berdi 27 dekabr, 18 parmonov98 (1,684 bal)
tanlangan 28 dekabr, 18 Kenjebaev
 
Eng yaxshi javob

   if($type === true)
    $this->email->isHTML(true);                                  // Set email format to HTML
   

kodimda mana shu qismida type contentni chaqirishda ikkinchi qiymat jo'natishni yoddan chiqibdi.

 

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...