当前位置: 首页>>代码示例>>PHP>>正文


PHP mail::getMX方法代码示例

本文整理汇总了PHP中mail::getMX方法的典型用法代码示例。如果您正苦于以下问题:PHP mail::getMX方法的具体用法?PHP mail::getMX怎么用?PHP mail::getMX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mail的用法示例。


在下文中一共展示了mail::getMX方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mail

 /**
  * Send email through socket
  *
  * This static method sends an email through a simple socket connection.
  * If {@link $smtp_relay} is set, it will be used as a relay to send the
  * email. Instead, email is sent directly to MX host of domain.
  *
  * @param string		$to			Email destination
  * @param string		$subject		Email subject
  * @param string		$message		Email message
  * @param string|array	$headers		Email headers
  * @throws Exception
  */
 public static function mail($to, $subject, $message, $headers = null)
 {
     $from = self::getFrom($headers);
     $H = 'Return-Path: <' . $from . ">\r\n";
     $from_host = explode('@', $from);
     $from_host = $from_host[1];
     $to_host = explode('@', $to);
     $to_host = $to_host[1];
     if (self::$smtp_relay != null) {
         $mx = array(gethostbyname(self::$smtp_relay) => 1);
     } else {
         $mx = mail::getMX($to_host);
     }
     foreach ($mx as $h => $w) {
         self::$fp = @fsockopen($h, 25, $errno, $errstr, self::$timeout);
         if (self::$fp !== false) {
             break;
         }
     }
     if (!is_resource(self::$fp)) {
         self::$fp = null;
         throw new Exception('Unable to open socket');
     }
     # We need to read the first line
     fgets(self::$fp);
     $data = '';
     # HELO cmd
     if (!self::cmd('HELO ' . $from_host, $data)) {
         self::quit();
         throw new Exception($data);
     }
     # MAIL FROM: <...>
     if (!self::cmd('MAIL FROM: <' . $from . '>', $data)) {
         self::quit();
         throw new Exception($data);
     }
     # RCPT TO: <...>
     if (!self::cmd('RCPT TO: <' . $to . '>', $data)) {
         self::quit();
         throw new Exception($data);
     }
     # Compose mail and send it with DATA
     $H = 'Return-Path: <' . $from . ">\r\n";
     $H .= 'To: <' . $to . ">\r\n";
     $H .= 'Subject: ' . $subject . "\r\n";
     $H .= $headers . "\r\n";
     $message = $H . "\r\n\r\n" . $message;
     if (!self::sendMessage($message, $data)) {
         self::quit();
         throw new Exception($data);
     }
     self::quit();
 }
开发者ID:ripplecrpht,项目名称:ripplecrpht,代码行数:66,代码来源:class.socket.mail.php


注:本文中的mail::getMX方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。