本文整理汇总了PHP中SMTP::auth方法的典型用法代码示例。如果您正苦于以下问题:PHP SMTP::auth方法的具体用法?PHP SMTP::auth怎么用?PHP SMTP::auth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMTP
的用法示例。
在下文中一共展示了SMTP::auth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fsockopen
// Gmail password
// 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.';
// connect to 'smtp.gmail.com' via SSL (TLS encryption) using port '465' and timeout '10' secounds
// make sure you have OpenSSL module (extension) enable on your php configuration
$c = fsockopen('tls://smtp.gmail.com', 465, $errno, $errstr, 10) or die($errstr);
// expect response code '220'
if (!SMTP::recv($c, 220)) {
die(print_r($_RESULT));
}
// EHLO/HELO
if (!SMTP::ehlo($c, 'localhost')) {
SMTP::helo($c, 'localhost') or die(print_r($_RESULT));
}
// AUTH LOGIN/PLAIN
if (!SMTP::auth($c, $f, $p, 'login')) {
SMTP::auth($c, $f, $p, 'plain') or die(print_r($_RESULT));
}
// MAIL FROM
SMTP::from($c, $f) or die(print_r($_RESULT));
// RCPT TO
SMTP::to($c, $t) or die(print_r($_RESULT));
// DATA
SMTP::data($c, $m) or die(print_r($_RESULT));
// RSET, optional if you need to send another mail using this connection '$c'
// SMTP::rset($c) or die(print_r($_RESULT));
// QUIT
SMTP::quit($c);
// close connection
@fclose($c);
echo 'Sent !';
示例2: fsockopen
require_once 'XPM4/SMTP.php';
// path to 'SMTP.php' file from XPM4 package
// standard mail message RFC2822
$m = 'From: duitasuo 团队' . "\r\n" . 'To:' . $to . "\r\n" . 'Subject:' . $subject . "\r\n" . 'Content-Type: text/plain' . "\r\n\r\n" . $body;
// connect to 'smtp.gmail.com' via SSL (TLS encryption) using port '465' and timeout '10' secounds
// make sure you have OpenSSL module (extension) enable on your php configuration
//error_reporting(0);
//phpinfo();
//$c = fsockopen('ssl://smtphm.sympatico.ca', 25);
$c = fsockopen('ssl://smtp.gmail.com', 465, $errno, $errstr, 10) or die($errstr);
// expect response code '220'
if (!SMTP::recv($c, 220)) {
die(print_r($_RESULT));
}
// EHLO/HELO
if (!SMTP::ehlo($c, 'localhost')) {
SMTP::helo($c, 'localhost') or die(print_r($_RESULT));
}
// AUTH LOGIN/PLAIN
if (!SMTP::auth($c, $username_smtp, $password_smtp, 'login')) {
SMTP::auth($c, $username_smtp, $password_smtp, 'plain') or die(print_r($_RESULT));
}
// MAIL FROM
SMTP::from($c, $from) or die(print_r($_RESULT));
// RCPT TO
SMTP::to($c, $to) or die(print_r($_RESULT));
// DATA
//SMTP::data($c, $m) or die(print_r($_RESULT)); // RSET, optional if you need to send another mail using this connection '$c'
SMTP::data($c, $m) or die(print_r($_RESULT));
SMTP::quit($c);
@fclose($c);