8791 sujets

Développement web côté serveur, CMS

Bonjour,
Nous sommes présentement a essayer de mettre en place un formulaire de contact.

Malheureusement, impossible de recevoir de mail sur ma boîte mail au bureau. Le support technique de notre serveur nous dit que le problème doit se situer au niveau du script et qu'il manquerait une authentification, c'est ce qui a été fait. Le script fonctionne pourtant, puisqu'il est possible de recevoir les mail du formulaire sur un compte autre, genre gmail.

Quelqu'un a-t-il une idée de ce qui peu causer le problème?

Voici le code de la page:
<?php
//require_once 'Mail.php';
require_once("./phpmailer/class.phpmailer.php");
	define("FIELD_REQUIRED", 1);
	define("FIELD_LENGTH", 2);
	define("FIELD_INVALID", 3);
	define("UPLOAD_WRONG_TYPE", 4);
	define("UPLOAD_MAX_FILESIZE", 5);
	define("UPLOAD_MOVE", 6);

	class Soumission {
		public $prenom;
		public $nom;
		public $adresse;
		public $ville;
		public $province;
		public $cp;
		public $pays;
		public $tel;
		public $courriel;
		public $departement;
		public $sujet;
		public $message;
		public $upload;
		
		/* CONFIG */
		public $allowedType = array(
			".jpg" => "image/jpeg"
		);
		
		private $upload_path;
		private $maxFilesize = 2097152;
		private $validDepartements = array("vente" => "Vente",
											"infos" => "Informations",
											"commentaires" => "Commentaires");
		private $smtpEmail = "noreply@ggtelecom.ca";
		private $smtpUsername = "noreply+ggtelecom.ca";
		private $smtpPassword = "mot de passe";
		private $smtpHost = "mail.ggtelecom.ca";
		
		/* false = pas d'erreur
		 * FIELD_REQUIRED = Champs requis
		 * FIELD_LENGTH = Longueur du champs
		 */
		public $error = array(
			"prenom" => false,
			"nom" => false,
			"adresse" => false,
			"ville" => false,
			"provinve" => false,
			"cp" => false,
			"pays" => false,
			"tel" => false,
			"courriel" => false,
			"departement" => false,
			"sujet" => false,
			"message" => false,
			"upload" => false
		);
		
		public function __construct(){
			if(isset($_POST['send'])){
				//prenom
				$this->prenom = filter_var($_POST["prenom"], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_HIGH);
				$this->prenom = filter_var($this->prenom, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
				//nom
				$this->nom = filter_var($_POST["nom"], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_HIGH);
				$this->nom = filter_var($this->nom, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
				//adresse
				$this->adresse = filter_var($_POST["adresse"], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_HIGH);
				$this->adresse = filter_var($this->adresse, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
				//ville
				$this->ville = filter_var($_POST["ville"], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_HIGH);
				$this->ville = filter_var($this->ville, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
				//province
				$this->province = filter_var($_POST["province"], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_HIGH);
				$this->province = filter_var($this->province, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
				//code postal
				$this->cp = filter_var($_POST["cp"], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_HIGH);
				$this->cp = filter_var($this->cp, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
				//pays
				$this->pays = filter_var($_POST["pays"], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_HIGH);
				$this->pays = filter_var($this->pays, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
				//telephone
				$this->tel = filter_var($_POST["tel"], FILTER_SANITIZE_NUMBER_FLOAT);
				//courriel
				$this->courriel = filter_var($_POST["courriel"], FILTER_SANITIZE_EMAIL);
				//departement
				$this->departement = filter_var($_POST["departement"], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_HIGH);
				$this->departement = filter_var($this->departement, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
				//sujet
				$this->sujet = filter_var($_POST["sujet"], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_HIGH);
				$this->sujet = filter_var($this->sujet, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
				//message
				$this->message = filter_var($_POST["message"], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_HIGH);
				$this->message = filter_var($this->message, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW);
				//upload
				$this->upload = !empty($_FILES['upload']['name'])?$_FILES['upload']:FALSE;

			}
		}
		
		public function ErrorCount() {
			return array_sum($this->error);	
		}
		
		public function validation(){
			//vérification des champs requis
			$this->error['prenom'] = empty($this->prenom)?FIELD_REQUIRED:false;
			$this->error['nom'] = empty($this->nom)?FIELD_REQUIRED:false;
			$this->error['courriel'] = empty($this->courriel)?FIELD_REQUIRED:false;
			$this->error['departement'] = $this->departement == "null"?FIELD_REQUIRED:false;
			$this->error['sujet'] = empty($this->sujet)?FIELD_REQUIRED:false;
			$this->error['message'] = empty($this->message)?FIELD_REQUIRED:false;
			
			if($this->ErrorCount() == 0) {
				//vérification de la longueyr des champs
				$this->error['prenom']= (strlen($this->nom) > 20)?FIELD_LENGTH:false;
				$this->error['nom']= (strlen($this->nom) > 20)?FIELD_LENGTH:false;
				
				$this->error['courriel']= (!filter_var($this->courriel, FILTER_VALIDATE_EMAIL))?FIELD_INVALID:false; //validation de l'email
				
				$this->error['departement'] = !isset($this->validDepartements[$this->departement])?FIELD_INVALID:false; //validation des departement
				
				if($this->upload !== FALSE) {
					//vérification du type par extension
					$ext = strrpos(".", $this->upload['name']);
					$ext = substr($this->upload['name'], $ext, strlen($this->upload['name']) - $ext);
					$this->error['upload'] = !isset($this->allowedType[$ext])?UPLOAD_WRONG_TYPE:false;
					if($this->ErrorCount() > 0)
						return;
					
					//vérification du type par MIME
					$this->error['upload'] = !in_array($this->upload['type'])?UPLOAD_WRONG_TYPE:false;
					if($this->ErrorCount() > 0)
						return;
						
					//vérification du poids du fichier
					$this->error['upload'] = (filesize($this->upload['tmp_name']) > $maxFilesize)?UPLOAD_MAX_FILESIZE:false;
					if($this->ErrorCount() > 0)
						return;
					
					//move le fichier
					$this->upload_path = "./tmp/mail_" . time();
					$this->error['upload'] = !move_uploaded_file($this->upload['tmp_name'], $this->upload_path)?UPLOAD_MOVE:false;
					if($this->ErrorCount() > 0)
						return;
				}
			}
		}
		
		public function sendMail() {
			if($this->ErrorCount() == 0) {
				$from = "NoReply Spypoint <".$this->smtpEmail.">";
				$to = "moi@spypoint.com";
				$subject = "[" . $this->validDepartements[$this->departement] . "] Demande de contact sur Site Web";
				$body = $this->message;
				
				$mail = new PHPMailer();  // create a new object
				$mail->IsSMTP(); // enable SMTP
				$mail->SMTPDebug = 1;  // debugging: 1 = errors and messages, 2 = messages only
				$mail->SMTPAuth = true;  // authentication enabled
				$mail->Host = 'mail.spypoint.com';
				$mail->Port = 587; 
				$mail->Username = "noreply+ggtelecom.ca";  
				$mail->Password = $this->smtpPassword;           
				$mail->SetFrom($this->smtpEmail, "NoreplySpypoint");
				$mail->Subject = $subject;
				$mail->Body = $body;
				$mail->AddAddress($to);
				if(!$mail->Send()) {
					$error = 'Mail error: '.$mail->ErrorInfo; 
					return false;
				} else {
					$error = 'Message sent!';
					return true;
				}
				
			}
		}
	}
	
	$service = "bla@ggtelecom.ca";
	$vente = "blas@ggtelecom.ca";
	$info = "bla@ggtelecom.ca";
	$comm = "bla@ggtelecom.ca";
	
?>

Modifié par juliesunset (21 Dec 2011 - 22:43)
Salut,

Vérifie tes paramètres smtp server en glissant ce petit fichier php sur ton serveur:
<?php
phpinfo();
?>


tu nommes ton fichier comme tu veux et tu te rends sur ce fichier par le navigateur.
Serait-il possible que ton email soit bloqué par le filtre de spam de ton programme de messagerie (puisque tu semble bien le recevoir sur Gmail).

Si c'est le cas, tu devrais jeter un oeil à tes SPF (ça se configure avec tes settings de DNS sur ton serveur).

Je dis ça comme ça puisqu'en soit si tu le reçois sur Gmail tu devrais théoriquement le recevoir ailleurs; mais ce n'est possiblement pas ça.

Voici un peu de documentation:
http://www.ipswitch.com/support/ics/guides/imailserver/8_2/imailughtml/Chapter%202%20config12.html

Et un outil pour tester:
http://www.kitterman.com/spf/validate.html
Bonjour!

Bon en fait on a enfin réussi à faire passer les mail. Effectivement ils passait par les filtres anti-spam de mon serveur.

Nous tournions en rond car malgré le fait que nous avions bien créer l'accès... ça ne passait pas. En fait, l'accès n'avait pas été créer au bon endroit. Détails que mon hébergeur ne m'avait pas mentionné jusqu'à maintenant.

Cela dit maintenant ça fonctionne, il ne reste plus qu'à mettre le formulaire en place!