本文整理汇总了PHP中SMTP::mxconnect方法的典型用法代码示例。如果您正苦于以下问题:PHP SMTP::mxconnect方法的具体用法?PHP SMTP::mxconnect怎么用?PHP SMTP::mxconnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMTP
的用法示例。
在下文中一共展示了SMTP::mxconnect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: explode
$to = 'client@destination.net';
// to mail address
$subj = 'Hello World!';
// mail subject
$text = 'Text version of message.';
// text/plain version of message
$html = '<b>HTML</b> version of <u>message</u>.';
// text/html version of message
// CONFIGURATION ------------------
// set text/plain version of message
$msg1 = MIME::message($text, 'text/plain');
// set text/html version of message
$msg2 = MIME::message($html, 'text/html');
// compose message in MIME format
$mess = MIME::compose($msg1, $msg2);
// standard mail message RFC2822
$body = 'From: ' . $from . "\r\n" . 'To: ' . $to . "\r\n" . 'Subject: ' . $subj . "\r\n" . $mess['header'] . "\r\n\r\n" . $mess['content'];
// get client hostname
$expl = explode('@', $to);
// connect to SMTP server (direct) from MX hosts list
$conn = SMTP::mxconnect($expl[1]) or die(print_r($_RESULT));
// send mail
$sent = SMTP::send($conn, array($to), $body, $from);
// print result
if ($sent) {
echo 'Sent !';
} else {
print_r($_RESULT);
}
// disconnect from SMTP server
SMTP::disconnect($conn);
示例2: error_reporting
error_reporting(E_ALL);
// php errors
define('DISPLAY_XPM4_ERRORS', true);
// display XPM4 errors
// path to 'SMTP.php' file from XPM4 package
require_once '../SMTP.php';
$f = 'me@mydomain.net';
// from mail address
$t = 'client@destination.net';
// to mail address
$p = 'my@address.net';
// return-path
// standard mail message RFC2822
$m = 'From: ' . $f . "\r\n" . 'To: ' . $t . "\r\n" . 'Subject: test' . "\r\n" . 'Content-Type: text/plain' . "\r\n\r\n" . 'Text message.';
// get client hostname
$h = explode('@', $t);
// optional, connect to the internet using IP '127.0.0.1'
$r = stream_context_create(array('socket' => array('bindto' => '127.0.0.1:0')));
// connect to SMTP server (direct) from MX hosts list to port '25' and timeout '10' secounds
// optional, set hostname 'localdomain.net' for EHLO/HELO SMTP dialog
$c = SMTP::mxconnect($h[1], 25, 10, 'localdomain.net', $r) or die(print_r($_RESULT));
// send mail and set return-path '$p' in 'MAIL FROM' SMTP dialog
$s = SMTP::send($c, array($t), $m, $p);
// print result
if ($s) {
echo 'Sent !';
} else {
print_r($_RESULT);
}
// disconnect
SMTP::disconnect($c);