Bonjour,

J'ai cette fonction standard qui a toujours fonctionné et, du jour au lendemain, elle a cessé de fonctionner. J'utilise PHP 5.2 et je n'ai fait aucune mise à jour sur le serveur. Mon serveur SMTP fonctionne bien car je peux toujours envoyer des courriels simples, les courriels avec pièce jointe ne partent plus. J'aimerais avoir vos commentaires quant à la forme du courriel généré au cas où ce serait cette forme qui ne correspondrait plus à des standards plus stricts.

Note : La fonction retourne true même lorsque le courriel n'est pas envoyé...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
function sendmail($to, $from, $subject, $body, $file = NULL, $filename = NULL, $hash = NULL, $confirmer_reception = true) {
	if($hash == NULL) $random_hash = $random_hash = md5(date('r', time()));
	else $random_hash = $hash;
	$config = get_config();
 
	ini_set("SMTP", $config["smtp"]); 
	ini_set('sendmail_from', $from);
	$headers  = "From: Sender <".$from.">\r\nReply-To: Receiver <".$from.">\r\n";
	if($confirmer_reception == true) {
		$headers .= "Return-Receipt-To: ".$from."\r\n";
		$headers .= "Disposition-Notification-To: ".$from."\r\n";
	}
	if($file != NULL) {
		$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
		$logo = chunk_split(base64_encode(file_get_contents("../img/logo_couleur.png")));
		ob_start();
		print("--PHP-mixed-".$random_hash."\r\n"); 
		print("Content-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"\r\n\r\n");
		print("--PHP-alt-".$random_hash ."\r\n");
		print("Content-Type: text/HTML; charset=\"iso-8859-1\"\r\n");
		print("Content-Transfer-Encoding: 7bit\r\n\r\n");
		print($body."\r\n");
		print("--PHP-alt-".$random_hash."--\r\n\r\n");
		if($filename != NULL) { 
	  	$attachment = chunk_split(base64_encode(file_get_contents($file)));
			print("--PHP-mixed-".$random_hash."\r\n");
			print("Content-Type: application/pdf; name=\"".basename($filename)."\"\r\n");
			print("Content-Transfer-Encoding: base64 \r\n");
			print("Content-Disposition: attachment \n\n");
			print($attachment."\n\n");
			print("--PHP-alt-".$random_hash."--\r\n");
		}
		print("--PHP-mixed-".$random_hash."\r\n");
		print("Content-Type: image/png; name=\"logo.png\"\r\n");
		print("Content-Transfer-Encoding: base64 \r\n");
		print("Content-Disposition: attachment \n\n");
		print($logo."\n\n");
		print("--PHP-alt-".$random_hash."--\r\n");
		$body = ob_get_clean();
	}
	else $headers .= "Content-Type: text/HTML; boundary=\"PHP-alt-".$random_hash."\"";
 
	return mail($to, $subject, $body, $headers);
}