1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| $SmtpServer="mail.domaine.com";
$SmtpPort="26";
$SmtpUser="directeur@domaine.com";
$SmtpPass="motdepasse";
class SMTPClient
{
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $nom, $tel, $body)
{
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->nom = $nom;
$this->tel = $tel;
$this->body = $body;
if ($SmtpPort == "")
{
$this->PortSMTP = 26;
}else{
$this->PortSMTP = $SmtpPort;
}
}
function SendMail()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
{
fputs ($SMTPIN, "EHLO ".$_SERVER['HTTP_HOST']."\r\n");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login\r\n");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."\r\n");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."\r\n");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->nom."\r\n".$this->tel."\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
}
return $talk;
}
}
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$to = ( isset($_POST['to']) && strtolower($_POST['to'])==="webmestre" ) ? "directeur@domaine.com" : "webmestre@domaine.com";
$nom = isset($_POST['nom']) ? preg_replace( "/[^\s\.\-a-zA-Z]/", "", ucwords(strtolower($_POST['nom']))) : "";
$tel = isset($_POST['tel']) ? preg_replace( "/[^\:\s\-0-9a-zA-Z]/", "", $_POST['tel'] ) : "";
$from = isset($_POST['from']) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['from']) : "";
$subject = "Vous avez un message visiteur";
$body = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", ucfirst($_POST['message'])) : "";
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $nom, $tel, $body);
$SMTPChat = $SMTPMail->SendMail();
} |
Partager