[PHPMailer] Authentification SMTP
Bonjour à tous !
J'ai une configuration smtp avec authentification (password). Pour faire les tests de la fonction mail(), j'ai besoin de configurer php.ini.
Les lignes habituelles
Code:
1 2
| SMTP = serverName
sendmail_from= userName |
pour win32 ne suffisent pas.:?
Existe-t-il un paramètre à ajouter dans php.ini pour indiquer qu'il s'agit d'un serveur avec authentification, et où je pourrais lui donner le mot de passe et l'utilisateur ?
Ou faut-il que je passe par autre chose dans mon code php pour passer l'authentification ?
Merci de vos réponses.
Petit souci de comprenette
J'ai essayé cette solution (phpMailer) qui semble correspondre à mes besoins.
Cependant, je rencontre un prob qui m'échappe...
Code:
Mailer Error: Language string failed to load: recipients_failed...
:? :?
Pourais-je avoir un petit éclairage ?
Merci encore,
Code pour envoyer un mail via GMail (SMTP)
Je viens de tester PHPMail en me servant du code du précédent message. J'ai perdu bcp de temps ! Voici le code qui fonctionne. J'ai eu des difficultés car l'exécution bloquait dans la fonction PHPMailer::RFCDate(), avec un warning dans la console
Code:
1 2
|
date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '1.0/no DST' instead |
La solution a été d'ajouter la ligne date_default_timezone_set("Europe/Zurich"); au début du script.
Code:
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
|
<?php
// example on using PHPMailer with GMAIL
include("class.phpmailer.php");
include("class.smtp.php"); // note, this is optional - gets called from main class if not already loaded
date_default_timezone_set("Europe/Zurich");
$mail = new PHPMailer();
//$body = file_get_contents('examples/contents.html"); // $mail->getFile(...) is invalid !
$body = "<body style=\"margin: 10px;\">
<div style=\"width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;\">
<br>
This is a test of PHPMailer.<br>
<br>
This particular example uses <strong>HTML</strong>, with a <div> tag and inline<br>
styles.<br>
</div>
</body>
";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "yy.zzz@gmail.com"; // GMAIL username
$mail->Password = "monpw"; // GMAIL password
$mail->From = "yy.zzz@gmail.com";
$mail->FromName = "YY";
$mail->Subject = "This is the subject";
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("yy.zzz@gmail.com","JP");
$mail->AddAttachment("C:/Development/ToolsPHP/PHPMailer_v5.1/examples/images/phpmailer.gif"); // attachment
$mail->AddAddress("xxx@romandie.com","XXX");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?> |