bueno es un probelma q tengo en una d mis paginas, el servidor no acepta el SMTP por cuestion de seguridad anti spam, entonces ellos usan SMTP_AUTH, quisiera saber como se haria una conexion SMTP_AUth, la cosa es q no tengo mucha experiensia en php pues hasta hace pcoo empeze a aprender aki les dejo el codigo q se usa para mandar los mensajes y todo y la conexion al smtp este mismo codigo es el q tengo q modifica, solo es la parte del codigo
class smtpSession {
var $conn;
var $info;
// Initializing Class
function smtpSession($host, $port = "25", $user = null, $pass = null) {
$this->info["host"] = $host;
$this->info["port"] = $port ? $port : "25";
$this->info["user"] = $user;
$this->info["pass"] = $pass;
if (class_exists("conf")) {
$this->info["from-mail"] = conf::getkey("core", "site.contact_mail");
$this->info["from-name"] = conf::getkey("core", "site.contact_mail");
} else {
$this->info["from-mail"] = GEKKO_SMTP_FROM_EMAIL;
$this->info["from-name"] = GEKKO_SMTP_FROM_NAME;
}
return $this->connect();
}
// Opens a connection with SMTP server
function connect() {
$this->conn = new remoteConnection($this->info["host"], $this->info["port"]);
if ($this->conn->status()) {
// connected, now saying hello!
return $this->login();
} else {
// there was a connection error for some strange reason
trigger_error("Couldn't open connection to SMTP server.",E_USER_ERROR);
return false;
}
}
// Sending creentials
function login() {
// Please read rfc0821 (or if you're too lazy just sniff a conversation between your e-mail client
// and one random smtp server)
$this->chat("220", "EHLO ".$this->info["host"]."\r\n");
$ehlo = $this->conn->read();
// getting server supported auth methods (read rfc2554)
// http://www.technoids.org/saslmech.html
if ($this->info["user"] && preg_match_all("/\d{3}-AUTH\s(.*)/", $ehlo, $match) && isset($match[1][0])) {
$methods = explode(" ", $match[1][0]);
if (in_array("LOGIN", $methods)) {
$this->conn->write("AUTH LOGIN\r\n");
$this->chat("334", base64_encode($this->info["user"])."\r\n");
$this->chat("334", base64_encode($this->info["pass"])."\r\n");
} else {
trigger_error("Unsupported SMTP AUTH type.", E_USER_ERROR);
}
if (!$this->chat("235", "", true))
trigger_error("Incorrect SMTP Username or Password.", E_USER_ERROR);
} else {
$this->chat("220", "HELO ".$this->info["host"]."\r\n");
$this->chat("250");
}
return true;
}
// Sends an e-mail
function send($to, $subject, $message, $content_type = "text/plain", $headers = null) {
//
$this->conn->write("MAIL FROM: <".$this->info["from-mail"].">\r\n");
// can handle multiple recipients sepparated by commas
$ato = explode(",", $to);
foreach ($ato as $addr) {
$this->chat("250", "RCPT TO: <".trim($addr).">\r\n");
}
// telling server that the following data is a message
$this->chat("250", "DATA\r\n");
$this->chat("354");
// common headers
$this->conn->write("Mime-Version: 1.0\r\n");
$this->conn->write("Content-Type: $content_type\r\n");
$this->conn->write("Subject: $subject\r\n");
$this->conn->write("From: ".$this->info["from-name"]." <".$this->info["from-mail"].">\r\n");
$this->conn->write("To: <".$to.">\r\n");
$this->conn->write("Date: ".date("r")."\r\n");
$this->conn->write("X-Mailer: Gekko/".GEKKO_VERSION."\r\n");
$this->conn->write("X-Gekko-Tag: ".(isset($GLOBALS["USER"]["id"]) ? $GLOBALS["USER"]["id"] : "?")."@".IP_ADDR."\r\n");
if (GEKKO_SMTP_EXTRA_HEADERS)
$headers .= GEKKO_SMTP_EXTRA_HEADERS;
if ($headers)
$this->conn->write($headers);
// message body
$this->conn->write("\r\n");
$this->conn->write($message);
$this->conn->write("\r\n.\r\n");
// expecting confirmation
$this->chat("250");
}
/**
* chat(expecting, answer, hide_errors);
* Sends $answer to server after receiving the expected answer
*/
function chat($expecting, $answer = null, $hide_errors = false) {
// reading what server is saying
$data = $this->conn->read();
// checking if this was an expected response code (first 3 numbers)
if (substr(trim($data), 0, 3) == $expecting) {
if ($answer)
$this->conn->write($answer);
return true;
} else {
if ($hide_errors)
return false;
trigger_error("S: \"".trim($data)."\", expecting: \"$expecting\"", E_USER_ERROR);
}
}
// closing connection
function bye() {
$this->conn->write("QUIT\r\n");
$this->conn->close();
}
}
function sendmail($to, $subject, $message, $content_type = "text/plain", $headers = null) {
// preventing possible spam attacks
$to = trim(preg_replace("/[\r|\n](.*?)/", "", $to));
$subject = trim(preg_replace("/[\r|\n](.*?)/", "", $subject));
$message = trim(preg_replace("/[\r|\n]\.[\r|\n](.*?)/", "", $message));
if (conf::getkey("core", "smtp.enable")) {
$smtp = new smtpSession(conf::getkey("core", "smtp.host"), conf::getkey("core", "smtp.port"), conf::getkey("core", "smtp.user"), conf::getkey("core", "smtp.pass"));
if ($smtp->conn->status()) {
$smtp->send($to, $subject, $message, $content_type, $headers);
}
$smtp->bye();
} else {
if (!$headers)
$headers = "";
$headers .= "Mime-Version: 1.0\r\n";
$headers .= "Content-Type: $content_type\r\n";
$headers .= "From: ".conf::getkey("core", "site.name")." <".conf::getkey("core", "site.contact_mail").">\r\n";
$headers .= "X-Gekko-Tag: ".(isset($GLOBALS["USER"]["id"]) ? $GLOBALS["USER"]["id"] : "0")."@".IP_ADDR."\r\n";
$headers .= "Date: ".date("r")."\r\n";
mail($to, $subject, $message, trim($headers));
}
}
?>