dragonmeng2002 2012-07-23 01:03
浏览 330

如何使用$ mail-> SMTPDebug作为字符串?

I want to echo "Fail" if strlen $mail->SMTPDebug is more than 10. But I don't know how to use $mail->SMTPDebug as a string. The below line in the function enables the debugging.

$mail->SMTPDebug  = 1;     

But can't use my if statement on it in my function. How can I do that ?

function mailsender($val,$yollayan,$sifresi,$name,$subject,$message) {

$mail = new PHPMailer();  
$mail->IsSMTP();               
$mail->SMTPDebug  = 1;          
$mail->SMTPAuth = true;         
$mail->SMTPSecure = "tls";      

$mail->Username   = $yollayan;
$mail->Password   = $sifresi;

$mail->Host = "smtp.live.com";  
$mail->Port = "587";  


$mail->From = $yollayan;
$mail->Fromname = $name;
$mail->name = $name;


$mail->Subject = $subject;  
$mail->Body = $message;  
$mail->AddAddress($val);   
$mail->send();

}
  • 写回答

2条回答 默认 最新

  • douci1677 2012-07-23 01:22
    关注

    You have to make child class of PHPMailer and redefine edebug method to store output in variable:

    class MyPHPMailer extends PHPMailer {
    
      public $DbgOut = '';
    
      private function edebug($str) {
        $this->DbgOut .= $str;
      }
    
    }
    

    And you call it like this:

    function mailsender($val, $yollayan, $sifresi, $name, $subject, $message) {
    
      $mail = new MyPHPMailer();  
      $mail->IsSMTP();               
      $mail->SMTPDebug  = 1;          
      $mail->SMTPAuth = true;         
      $mail->SMTPSecure = "tls";      
    
      $mail->Username   = $yollayan;
      $mail->Password   = $sifresi;
    
      $mail->Host = "smtp.live.com";  
      $mail->Port = "587";  
    
    
      $mail->From = $yollayan;
      $mail->Fromname = $name;
      $mail->name = $name;
    
    
      $mail->Subject = $subject;  
      $mail->Body = $message;  
      $mail->AddAddress($val); 
      $mail->send();
    
      if(strlen($mail->DbgOut) > 10)
        echo 'Failed'.PHP_EOL;
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么