IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

send mail en php [PHP 5.2]


Sujet :

Langage PHP

  1. #1
    Nouveau membre du Club
    Inscrit en
    Août 2009
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 51
    Points : 35
    Points
    35
    Par défaut send mail en php
    Salut tous le monde.
    Alors je souhaite fortement avoir votre aide dans mon problème d'envoi de mail depuis php.
    donc j'ai crée un fichier mail.php dans le dossier "www" dont le code est le suivant:
    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
    <?php
    $mail = 'xxxx@gmail.com';
    if (!preg_match("#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#", $mail)) 
    {
    	$passage_ligne = "\r\n";
    }
    else
    {
    	$passage_ligne = "\n";
    }
    $message_txt = "Salut à tous";
    $message_html = "<html><head></head><body><b>Salut à tous</b></body></html>";
    $boundary = "-----=".md5(rand());
    $sujet = "Hey mon ami !";
    $header = "From: \"xxx xxx\"<xxxxxx@hotmail.com>".$passage_ligne;
    $header.= "Reply-to: \"xxx xxx\" <xxxxxx@hotmail.com>".$passage_ligne;
    $header.= "MIME-Version: 1.0".$passage_ligne;
    $header.= "Content-Type: multipart/alternative;".$passage_ligne." boundary=\"$boundary\"".$passage_ligne;
    $message = $passage_ligne.$boundary.$passage_ligne;
    $message.= "Content-Type: text/plain; charset=\"ISO-8859-1\"".$passage_ligne;
    $message.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
    $message.= $passage_ligne.$message_txt.$passage_ligne;
    $message.= $passage_ligne."--".$boundary.$passage_ligne;
    $message.= "Content-Type: text/html; charset=\"ISO-8859-1\"".$passage_ligne;
    $message.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
    $message.= $passage_ligne.$message_html.$passage_ligne;
    $message.= $passage_ligne."--".$boundary."--".$passage_ligne;
    $message.= $passage_ligne."--".$boundary."--".$passage_ligne;
    //=====Envoi de l'e-mail
    mail($mail,$sujet,$message,$header);
    //==========
    ?>
    et aussi j'ai modifié dans le répertoire apache le fichier php.ini comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    SMTP = smtp.live.com
    smtp_port = 25
    j'ai mis ça meme dans le ficher php.ini dans le répertoire conf_files.
    maintenant pour tester si ça marche j'ai ouvert Mozilla et j'ai tapé cette url:
    http://localhost/mail.php
    et voici l'erreur que j'ai obtenu :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Warning: mail() [function.mail]: SMTP server response: 550 5.7.3 Requested action aborted; user not authenticated in C:\Program Files\EasyPHP 2.0b1\www\mail.php on line 33
    donc la fonction mail();
    et bien sûr je reçois rien
    si vous avez une petite idée de ce qui passe plz help me!!
    Merci d'avance
    PS: je travaille sous Windows XP
    Cordialement

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    98
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 98
    Points : 86
    Points
    86
    Par défaut
    As tu redémarré Apache?

  3. #3
    Nouveau membre du Club
    Inscrit en
    Août 2009
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 51
    Points : 35
    Points
    35
    Par défaut
    Citation Envoyé par omageus Voir le message
    As tu redémarré Apache?
    ben oui j'ai redémarré Apache

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,
    Warning: mail() [function.mail]: SMTP server response: 550 5.7.3 Requested action aborted; user not authenticated in C:\Program Files\EasyPHP 2.0b1\www\mail.php on line 33
    Tu as besoin de faire une authentification SMTP, utilises phpmailer.

  5. #5
    Nouveau membre du Club
    Inscrit en
    Août 2009
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 51
    Points : 35
    Points
    35
    Par défaut
    ok merci je vais voir en utilisant ça

  6. #6
    Nouveau membre du Club
    Inscrit en
    Août 2009
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 51
    Points : 35
    Points
    35
    Par défaut
    salut
    j'ai téléchargé phpmailer j'ai modifier mon code comme suit:
    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
    <?php
    require "C:\Program Files\EasyPHP 2.0b1\www\phpmailer\class.phpmailer.php";
    $mail = new PHPmailer();
    $mail->IsSMTP();
    $mail->Host='smtp.gmail.com';
    $mail = 'xxxx@hotmail.com';
    if (!preg_match("#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#", $mail)) 
    {
    	$passage_ligne = "\r\n";
    }
    else
    {
    	$passage_ligne = "\n";
    }
    $message_txt = "Salut à tous";
    $message_html = "<html><head></head><body><b>Salut à tous</b></body></html>";
    $boundary = "-----=".md5(rand());
    $sujet = "Hey mon ami !";
    $header = "From: \"xxx xxx\"<xxxxxx@gmail.com>".$passage_ligne;
    $header.= "Reply-to: \"xxx xxx\" <xxxxxx@gmail.com>".$passage_ligne;
    $header.= "MIME-Version: 1.0".$passage_ligne;
    $header.= "Content-Type: multipart/alternative;".$passage_ligne." boundary=\"$boundary\"".$passage_ligne;
    $message = $passage_ligne.$boundary.$passage_ligne;
    $message.= "Content-Type: text/plain; charset=\"ISO-8859-1\"".$passage_ligne;
    $message.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
    $message.= $passage_ligne.$message_txt.$passage_ligne;
    $message.= $passage_ligne."--".$boundary.$passage_ligne;
    $message.= "Content-Type: text/html; charset=\"ISO-8859-1\"".$passage_ligne;
    $message.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
    $message.= $passage_ligne.$message_html.$passage_ligne;
    $message.= $passage_ligne."--".$boundary."--".$passage_ligne;
    $message.= $passage_ligne."--".$boundary."--".$passage_ligne;
    //=====Envoi de l'e-mail
    mail($mail,$sujet,$message,$header);
    //==========
    ?>
    sachant que j'ai maintenant modifier mon serveur smtp dans le fichier php.ini comme suit
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    SMTP = smtp.gmail.com
    smtp_port = 587
    j'ai maintenant cette erreur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Warning: mail() [function.mail]: SMTP server response: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 14sm72129fxm.13 in C:\Program Files\EasyPHP 2.0b1\www\mail.php on line 34
    j'ai essayé aussi avec le port 465 mais j'ai un pb de port
    help plz
    Merci d'avance

  7. #7
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Re,
    Tu as oublié l'authentification .
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $mail->Username="TonLogin";
    $mail->Password="TonMotDePass";

  8. #8
    Nouveau membre du Club
    Inscrit en
    Août 2009
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 51
    Points : 35
    Points
    35
    Par défaut
    ok merci

  9. #9
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 21
    Points : 17
    Points
    17
    Par défaut re
    salut
    j'ai testé le script mais j'ai ce message d'erreur
    Warning: mail() [function.mail]: SMTP server response: 530 5.7.1 Client was not authenticated

  10. #10
    Nouveau membre du Club
    Inscrit en
    Août 2009
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 51
    Points : 35
    Points
    35
    Par défaut
    hi
    Here are the steps to follow to send a mail:
    1 .Download PHPMailer from http://phpmailer.sourceforge.net
    2 .Extract to folder phpmailer
    3.Create a file email.php
    4 .Paste this code and change the values in blue as you need
    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
     
    require("phpmailer/class.phpmailer.php");
    $mail = new PHPMailer();
    $mail->IsSMTP(); // send via SMTP
    IsSMTP(); // send via SMTP
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "username@gmail.com"; // SMTP username
    $mail->Password = "password"; // SMTP password
    $webmaster_email = "username@doamin.com"; //Reply to this email ID
    $email="username@domain.com"; // Recipients email ID
    $name="name"; // Recipient's name
    $mail->From = $webmaster_email;
    $mail->FromName = "Webmaster";
    $mail->AddAddress($email,$name);
    $mail->AddReplyTo($webmaster_email,"Webmaster");
    $mail->WordWrap = 50; // set word wrap
    $mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
    $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
    $mail->IsHTML(true); // send as HTML
    $mail->Subject = "This is the subject";
    $mail->Body = "Hi,
    This is the HTML BODY "; //HTML Body
    $mail->AltBody = "This is the body when user views in plain text format"; //Text Body
    if(!$mail->Send())
    {
    echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
    echo "Message has been sent";
    }
    ?>
    5 .Open the file class.smtp.php in phpmailer directory
    6 .Paste this code
    $host = "ssl://smtp.gmail.com";
    $port = 465;
    before the line 104 #connect to the smtp server
    Hint: Search for #connect
    7 .Open this page in browser and it will send the email using GMail.

    I hope I helped you
    good luck

  11. #11
    Nouveau membre du Club
    Inscrit en
    Août 2009
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 51
    Points : 35
    Points
    35
    Par défaut
    Re Hi
    if you use hotmail smtp Remember to change the smtp!

  12. #12
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 21
    Points : 17
    Points
    17
    Par défaut
    merci mine87
    ce que je ne comprends pas
    username@doamin.com
    je le remplace par quoi
    parce que je ne suis pas hebergé je veux dire que mon script n'est pas utilisé dans un site web mais dans un logiciel php que je developpe

    je ne sais pas si vous me comprenez ou pas ?

  13. #13
    Nouveau membre du Club
    Inscrit en
    Août 2009
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 51
    Points : 35
    Points
    35
    Par défaut
    is the box with which you send the message. so the password is the password of the box:
    for example you send from a gmail box the smtp is :smtp.gmail.com
    and your username is xxx@gmail.com and password of your box is xxx@gmail.com yyyy

  14. #14
    Nouveau membre du Club
    Inscrit en
    Août 2009
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 51
    Points : 35
    Points
    35
    Par défaut
    Another little thing this code works without hosting

  15. #15
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 21
    Points : 17
    Points
    17
    Par défaut
    bonjour
    j'ai réessayé ce script avec xxx@live.fr mon compte xxxxxxxxx mon mot de passe yyy@live.fr l'adresse de destination
    <?php
    require("class.phpmailer.php");
    $mail = new PHPMailer();
    $mail->IsSMTP(); // send via SMTP
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "xxx@live.fr"; // SMTP username
    $mail->Password = "xxxxxxxxx"; // SMTP password
    $webmaster_email = "xxx@live.fr"; //Reply to this email ID
    $email= "yyy@live.fr"; // Recipients email ID
    $name="name"; // Recipient's name
    $mail->From = $webmaster_email;
    $mail->FromName = "Webmaster";
    $mail->AddAddress($email,$name);
    $mail->AddReplyTo($webmaster_email,"Webmaster");
    $mail->WordWrap = 50; // set word wrap
    $mail->IsHTML(true); // send as HTML
    $mail->Subject = "This is the subject";
    $mail->Body = "Hi,
    This is the HTML BODY "; //HTML Body
    $mail->AltBody = "This is the body when user views in plain text format"; //Text Body
    if(!$mail->Send())
    {
    echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
    echo "Message has been sent";
    }

    ?>

    mais toujours ce message d'erreur
    SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

    j'ai utilisé le serveur smtp.live.com et port 25

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Mail] send mail, php fusion, wamp
    Par neecride dans le forum Langage
    Réponses: 4
    Dernier message: 07/02/2009, 21h32
  2. [Mail] Serveur de mail en PHP sur serveur dédié
    Par dralik dans le forum Langage
    Réponses: 15
    Dernier message: 16/01/2006, 15h11
  3. [Mail] Le php pourrait il résoudre mon problème???
    Par mayoouketchup dans le forum Langage
    Réponses: 3
    Dernier message: 20/12/2005, 13h10
  4. [Mail] Transferer un mail en PHP.
    Par tissot dans le forum Langage
    Réponses: 2
    Dernier message: 04/10/2005, 19h23
  5. Probleme d'envois de mail serveur PHP/ASP
    Par oulahoup dans le forum ASP
    Réponses: 2
    Dernier message: 23/08/2005, 14h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo