Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Eu utilizo a função abaixo para enviar malas-direta e também para enviar e-mail quando efetua um compra, porém algumas vezes as pessoas dizem que não recebem o e-mail. Isto é um problema da função ou do servidor ?
<?php
class Smtp{
var $conn;
var $user;
var $pass;
var $debug = true;
var $x = "";
function Smtp($host){
$this->conn = fsockopen($host, 25, $errno, $errstr, 30);
$this->Put("EHLO $host");
}
function Auth(){
$this->Put("AUTH LOGIN");
$this->Put(base64_encode($this->user));
$this->Put(base64_encode($this->pass));
}
function Send($to, $from, $subject, $msg){
$this->Auth();
$this->Put("MAIL FROM: " . $from);
$this->Put("RCPT TO: " . $to);
$this->Put("DATA");
$this->Put($this->toHeader($to, $from, $subject));
$this->Put("\r\n");
$this->Put($msg);
$this->Put(".");
$this->Close();
if(isset($this->conn)){
return true;
}else{
return false;
}
}
function Put($value){
return fputs($this->conn, $value . "\r\n");
}
function toHeader($to, $from, $subject){
$header = "Message-Id: <". date('YmdHis').".". md5(microtime()).".". strtoupper($from) ."> \r\n";
$header .= "From: <" . $from . "> \r\n";
$header .= "To: <".$to."> \r\n";
$header .= "Subject: ".$subject." \r\n";
$header .= "Date: ". date('D, d M Y H:i:s O') ." \r\n";
$header .= "X-MSMail-Priority: High \r\n";
$header .= "Content-type: text/html; charset=iso-8859-1\r\n";
return $header;
}
function Close(){
$this->Put("QUIT");
if($this->debug == true){
while (!feof ($this->conn)) {
$x .= fgets($this->conn)."\n";
}
mysql_query("INSERT INTO email (...) VALUES (...)");
}
return fclose($this->conn);
}
}
//Enviar e-mail
$subject = "assunto";
$smtp = new Smtp("mail.servidor.com");
$smtp->user = "usuario";
$smtp->pass = "senha";
$smtp->debug = true;
if($smtp->Send($to,"x@servidor.ocm",$subject,$body)){echo"foi";}else{echo"erro";}
?>Carregando comentários...