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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| <?php
$SmtpServer="";
$SmtpPort="25";
$SmtpUser="";
$SmtpPass="";
// La class SMTP: C'est ici qui manque de quoi:
class SMTPClient
{
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $nom, $tel, $subject, $body)
{
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->nom = $nom;
$this->tel = $tel;
$this->subject = $subject;
$this->body = $body;
if ($SmtpPort == "")
{
$this->PortSMTP = 25;
}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->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
}
return $talk;
}
}
// La validation du formulaire:
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$to = "moncourriel@duserveur.com";
$nom = isset($_POST['nom']) ? preg_replace( "/[^\s\.\-a-zA-Z]/", "", $_POST['nom'] ) : "";
$tel = isset($_POST['tel']) ? preg_replace( "/[^\-0-9]/", "", $_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:)/", "", $_POST['message'] ) : "";
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}
?>
<!-- Le formulaire: -->
<form method="post" action="" id="form">
<table class="bloctable" width="800px">
<caption><img src="/images/titlecontact.png" alt="" /></caption>
<tr><td class="titleTd1" width="20%">Contact:</td><td class="titleTd2" width="80%"><input readonly type='text' name="sub" value="Webmestre" /></td></tr>
<tr><td class="titleTd1">Nom:</td><td class="titleTd3"><input class="courriel tooltip" title="Votre courriel" required autocomplete="off" type='text' name="nom" placeholder="indiquer votre nom" maxlength="60" /></td></tr>
<tr><td class="titleTd1">Tel:</td><td class="titleTd3"><input class="courriel tooltip" title="Votre téléphone" required autocomplete="off" type='tel' name="tel" placeholder="555-555-1212" maxlength="25" pattern="\d{3}[\-]\d{3}[\-]\d{4}" /></td></tr>
<tr><td class="titleTd1">Email:</td><td class="titleTd3"><input class="courriel tooltip" title="Votre courriel" required autocomplete="off" type='email' name="from" placeholder="votre@courriel.com" maxlength="45" autofocus /></td></tr>
<tr><td class="titleTd1">Message :</td><td class="titleTd3"><textarea style="overflow-y:auto" class="courriel tooltip" title="votre message et assez-vous de répondre au Captcha" rows="3" required autocomplete="off" name="message" placeholder="Écrire votre message ici" maxlength="500"></textarea></td></tr>
<tr><td class="titleTd1"></td><td><input class="tooltip" title="Vous pouvez envoyer..." type="submit" value=" Envoyer" /></td></tr>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
{ echo '<tr><td class="titleTd1"> Résultat:</td><td class="titleTd2"><input class="tooltip" title="Une réponse sous peu..." readonly type=\'text\' name="sub" value="Message envoyé avec succès, MERCI!" /></td></tr>'; }
?>
</table>
</form> |
Partager