本文整理汇总了PHP中SMTP::Connected方法的典型用法代码示例。如果您正苦于以下问题:PHP SMTP::Connected方法的具体用法?PHP SMTP::Connected怎么用?PHP SMTP::Connected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMTP
的用法示例。
在下文中一共展示了SMTP::Connected方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkSMTP
function checkSMTP($smtp_server, $smtp_port = 25, $username, $password, $auth_enabled = false, $tls_enabled = true)
{
require_once "libs/phpmailer/class.smtp.php";
$smtp = new SMTP();
$smtp->Connect($smtp_server, $smtp_port);
if (!$smtp->Connected()) {
return array("ERROR" => "Failed to connect to server", "SMTP_ERROR" => $smtp->getError());
}
if (!$smtp->Hello()) {
return array("ERROR" => "Failed to send hello command", "SMTP_ERROR" => $smtp->getError());
}
if ($tls_enabled) {
if (!$smtp->StartTLS()) {
return array("ERROR" => "Failed to start TLS", "SMTP_ERROR" => $smtp->getError());
}
}
if ($auth_enabled) {
if (!$smtp->Authenticate($username, $password)) {
$error = $smtp->getError();
if (preg_match("/STARTTLS/", $error['smtp_msg'])) {
return array("ERROR" => "Authenticate Error, TLS must be activated", "SMTP_ERROR" => $smtp->getError());
} else {
return array("ERROR" => "Authenticate not accepted from server", "SMTP_ERROR" => $smtp->getError());
}
}
}
return true;
}
示例2: send
public function send($para = array(), $single = false, $priority = 3, $extHeader = "")
{
if ($this->from == '') {
$this->from = ini_get('sendmail_from');
}
$this->addHeader("Return-Path", $this->from);
$mail_list = array_merge($this->to, $this->cc, $this->bcc);
if ($single == false) {
if (count($this->to) > 0) {
$this->addHeader("To", implode(', ', $this->formatEmail($this->to)));
}
if (count($this->cc) > 0) {
$this->addHeader("Cc", implode(', ', $this->formatEmail($this->cc)));
}
if (count($this->bcc) > 0) {
$this->addHeader("Bcc", implode(', ', $this->formatEmail($this->bcc)));
}
}
$this->addHeader("From", $this->from);
if (count($this->reply) > 0) {
$this->addHeader("Reply-To", implode(', ', $this->formatEmail($this->reply)));
}
$this->addHeader("Subject", $this->subject);
$this->addHeader("Message-ID", sprintf("<%s@%s>", md5(uniqid(time())), $_SERVER["HTTP_HOST"]));
if (!preg_match("/[1-5]/", $priority)) {
$priority = 3;
}
$this->addHeader("X-Priority", $priority);
$this->addHeader("X-Mailer", "MyStep_CMS");
$this->addHeader("MIME-Version", "1.0");
$mail_content = implode("\r\n", $this->headers) . "\r\n";
if (!empty($extHeader)) {
$mail_content .= $extHeader . "\r\n";
}
$mail_content .= $this->buildMail();
$info = "";
if (!empty($para['mode'])) {
require "class.smtp.php";
$smtp = new SMTP();
if (!$smtp->Connect(($para['mode'] == "ssl" || $para['mode'] == "ssl/tls" ? "ssl://" : "") . $para['host'], $para['port'], 10)) {
$this->Error("Cannot connect to the mail server!");
return false;
}
if (!$smtp->Hello($_SERVER["HTTP_HOST"])) {
$this->Error("Cannot send messege to the mail server!");
return false;
}
if ($para['mode'] == "tls" || $para['mode'] == "ssl/tls") {
if (!$smtp->StartTLS()) {
$this->Error("TLS error!");
return false;
}
$smtp->Hello($_SERVER["HTTP_HOST"]);
}
if (isset($para['user'])) {
if (!$smtp->Authenticate($para['user'], $para['password'])) {
$this->Error("Authenticate Failed!");
return false;
}
}
if (!$smtp->Mail(ini_get('sendmail_from'))) {
$this->Error("Bad sender email");
return false;
}
for ($i = 0, $m = count($mail_list); $i < $m; $i++) {
if ($smtp->Recipient($mail_list[$i][0])) {
$info = " sended!";
} else {
$info = " error!";
}
if ($this->log_fp) {
fwrite($this->log_fp, $mail_list[$i][0] . $info . "\n");
}
}
if (!$smtp->Data($mail_content)) {
$this->Error("Mail send Failed!");
return false;
}
$smtp->Reset();
if ($smtp->Connected()) {
$smtp->Quit();
$smtp->Close();
}
} else {
for ($i = 0, $m = count($mail_list); $i < $m; $i++) {
if (!@mail(formatEmail($mail_list[$i]), $this->subject, "", $mail_content)) {
$info = " sended!";
} else {
$info = " error!";
}
if ($this->log_fp) {
fwrite($this->log_fp, $mail_list[$i][0] . $info . "\n");
}
}
}
if ($this->log_fp) {
fclose($this->log_fp);
}
return true;
}