Más contenido relacionado
La actualidad más candente (18)
Similar a Email et PHP5 (20)
Más de Jean-Marie Renouard (8)
Email et PHP5
- 2. Le logo PHP est du domaine public
http://commons.wikimedia.org/wiki/File:PHP-logo.svg
Ce document est licencié sous licence
◦Attribution-NonCommercial-ShareAlike
◦CC BY-NC-SA
Plus de détails:
http://creativecommons.org/licenses/by-nc-sa/3.0/fr/
LightPath 2014© - http://www.jmrenouard.fr
2
- 3. Configuration PHP
Envoyer un message simple
Envoyer un message avec des copies
Envoyer un message en HTML
Autres APIs Mail
Envoyer un message avec pièces jointes
LightPath 2014© - http://www.jmrenouard.fr
3
- 5. API mail supporte SMTP
La configuration se trouve dans php.ini
[sendmail] smtp_server=mail.yourdomain.com smtp_port=25
LightPath 2014© - http://www.jmrenouard.fr
5
- 7. Mail: fonction principale d’envoi de mail
<?php
// Le message
$message = "Line 1nLine 2nLine 3";
$message = wordwrap($message, 70);
// Envoi du mail
mail(‘destinataire@example.com', 'Mon Sujet', $message);
?>
LightPath 2014© - http://www.jmrenouard.fr
7
- 8. $to = 'aidan@example.com' . ', '; // notez la virgule
$to .= 'wez@example.com'; // En-têtes additionnels
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "rn";
$headers .= 'From: Anniversaire <anniversaire@example.com>' . "rn";
$headers .= 'Cc: anniversaire_archive@example.com' . "rn";
$headers .= 'Bcc: anniversaire_verif@example.com' . "rn";
// Envoi
mail($to, $subject, $message, $headers);
LightPath 2014© - http://www.jmrenouard.fr
8
- 9. Le message en HTML
◦$message = ’<html>…</html>’;
Les entêtes MAIL pour l’HTML
$headers = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
L’envoi du email
mail($to, $subject, $message, $headers);
LightPath 2014© - http://www.jmrenouard.fr
9
- 10. API PHP trop pauvre
Utilisation API tiers préconisés.
LightPath 2014© - http://www.jmrenouard.fr
10
- 12. foreach ($list as $name => $address) { $this->email->clear(); $this->email->to($address); $this->email->from('your@example.com'); $this->email->subject(‘petit message '.$name); $this->email->message(‘Bonjour '.$name.' , et bonne journée.'); $this->email->send(); }
LightPath 2014© - http://www.jmrenouard.fr
12
- 13. $tr = new Zend_Mail_Transport_Smtp(‘smtp.gmail.com');
$mail->setFrom('a@gmail.com', 'Server');
$mail->addTo($to, 'a@gmail.com');
$mail->setSubject($subject);
$mail->setBodyText($body);
$mail->send();
LightPath 2014© - http://www.jmrenouard.fr
13
- 14. include('Mail.php');
$mail = Mail::factory("mail");
$headers = array(
"From"=>"me@example.com",
"Subject"=>"Test Mail«
);
$body = "This is a test! » ;
$mail->send("best@friend.com", $headers, $body);
LightPath 2014© - http://www.jmrenouard.fr
14
- 16. foreach ($list as $name => $address) { $this->email->clear(); $this->email->to($address); $this->email->from('your@example.com'); $this->email->subject(‘petit message '.$name); $this->email->message(‘Bonjour '.$name.' , et bonne journée.');
$this->email->attach('/path/to/photo1.jpg'); $this->email->send(); }
LightPath 2014© - http://www.jmrenouard.fr
16
- 17. $mail = new Zend_Mail();
$mail->setFrom('a@gmail.com', 'Server');
$mail->addTo($to, 'a@gmail.com');
$mail->setSubject($subject);
$mail->setBodyText($body);
$mail->createAttachment($someBinaryString);
$mail->createAttachment($myImage,
'image/gif',
Zend_Mime::DISPOSITION_INLINE,
Zend_Mime::ENCODING_BASE64);
$mail->send();
LightPath 2014© - http://www.jmrenouard.fr
17
- 18. include('Mail.php');
include_once('Mail_Mime/mime.php');
$msg = new Mail_mime() ;
$headers = array(
"From"=>"me@example.com",
"Subject"=>"Test Mail »
);
$body = "This is a test! » ;
$ msg ->addAttachment(« mon Fichier.txt »);
$mail =& Mail::factory('mail');
$mail->send("best@friend.com", $headers, $body);
LightPath 2014© - http://www.jmrenouard.fr
18
- 19. LightPath:
◦Société de conseil et d’ingénierie
◦Formations, Conseil, Audit et mise en oeuvre
◦jmrenouard@lightpath.fr
Jean-Marie RENOUARD
◦jmrenouard@gmail.com
◦Twitter: @jmrenouard
◦http://www.jmrenouard.fr
LightPath 2014© - http://www.jmrenouard.fr
19