phpmailer send pictures

 

php check email address

1  function PageIsMail( array  $email_arr ){
 2      foreach ( $email_arr  as  $email ) {
 3          // Regular mailbox matching (cannot start with -_.) 
4          if (! preg_match ("/^[0-9A-Za-z ][0-9A-Za-z-_.]*@([0-9a-z]+\\.[az]{2,3}(\\.[az]{2})?)$/ i", $email )){
 5              echo "(method1)invalid email: $email <br />" ;
 6              continue ;
 7          }
 8          // name is between 4 and 16 digits 
9          if ( strlen ( explode("@", $email )[0])<4 or strlen ( explode ("@", $email )[0])>16 ){
 10              echo "(method2)invalid email: $email <br />" ;
 11              continue ;
 12          }
 13          // Does the domain name exist (rely on the network, not recommended) 
14          if (checkdnsrr( explode ("@", $email )[1],"MX") === false ) {
 15              echo "(methodof3)invalid email: $email <br />" ;
 16              continue ;
17         }
18         echo "email: $email<br />";
19     }
20 }

 

 

phpmailer send email with image

code directly

 1 // 发送邮件
 2 function SendMail(){
 3     require_once("./msg/class.phpmailer.php");
 4     $mail = new PHPMailer();
 5     //$mail->SMTPDebug = 3;
 6     $this->mail=$mail;
 7     $this->mail->isSMTP();
 8     $this->mail->CharSet = 'UTF-8';
 9     $this->mail->Host = 'smtp.exmail.qq.com';
10     $this->mail->SMTPAuth = true;
11     $mail->Username = '[email protected]';
12     $mail->Password = 'pwd';
13     $this->mail->SMTPSecure = 'ssl';
14     $this->mail->Port = 465;
15     $this->mail->From = '[email protected]';
16     $this->mail->addAddress('[email protected]','toName');
17     $this->mail->isHTML(true);
18     $this -> mail ->Subject = 'Chinese Subject Test' ;
 19      $hmtl = '<i>Handsome guy</i>: <b>Hello</b>! ! ! <br><img src="./static/pic/xx.png" /><br><img src="./static/pic/xx.png" />' ;
 20      // With image processing, no The image is not processed, the image format is as above (the image is not formatted) 
21      $this -> mail ->Body = ProcessImg( $hmtl );
 22      $this -> mail ->AltBody = strip_tags ( $hmtl );
 23      if (! $this -> mail ->                  echo 'Mailer Error: ' . $this -> mail -> ErrorInfo;
 26      } else {
 27          echo 'Message has been sent' ;
 28      }
 29  }
 30  
31 // To process pictures in MailBody, add local pictures to attachments Send successfully 
32  function ProcessImg( $html ){
 33      $resutl = preg_match_all ('@<img src=.+? />@', $html , $matches );
 34      if (! $resutl ) return  $html ;
35     $trans = array();
36     foreach ($matches[0] as $key => $img) {
37         $id = 'img' . $key;
38         preg_match('/src="(.*?)"/', $html, $path);
39         if ($path[1]){
40             $this->mail->addEmbeddedImage($path[1], $id);
41             $trans[$img] = '<img src="cid:' . $id . '" />';
42         }
43     }
44     $html = strtr($html, $trans);
45     return $html;
46 }

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324660516&siteId=291194637