Home  >  Article  >  php教程  >  PHP使用pear_smtp发送简单邮件

PHP使用pear_smtp发送简单邮件

PHP中文网
PHP中文网Original
2016-05-22 17:22:281318browse

PHP使用pear_smtp发送简单邮件

<?php  
 require_once "vendor/autoload.php";  
   
 $from = "test<test@163.com>";  
 $to = "test <test@outlook.com>";  
 $subject = "Hi!";  
 $body = "Hi,\n\nHow are you?";  
   
 $host = "smtp.163.com";  
$port = "25"; 
 $username = "test@163.com";  
 $password = "test123";  
   
 $headers = array (&#39;From&#39; => $from,  
   &#39;To&#39; => $to,  
   &#39;Subject&#39; => $subject);  
 $smtp = Mail::factory(&#39;smtp&#39;,  
   array (&#39;host&#39; => $host,  
     &#39;port&#39; => $port,  
     &#39;auth&#39; => true, 
    // &#39;debug&#39;=>true, 
     &#39;username&#39; => $username,  
     &#39;password&#39; => $password));  
   
 $mail = $smtp->send($to, $headers, $body);  
   
 if (PEAR::isError($mail)) {  
   echo("<p>" . $mail->getMessage() . "</p>");  
  } else {  
   echo("<p>Message successfully sent!</p>");  
  }  
 ?>

                   

 以上就是PHP使用pear_smtp发送简单邮件的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn