Exemple #1
0
// 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 !';
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);