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 :

envoi mail php


Sujet :

Langage PHP

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2017
    Messages : 71
    Points : 50
    Points
    50
    Par défaut envoi mail php
    Bonjour,
    J'essaye d’envoyer un mail via php
    Cela fonctionne en partie je reçois bien un mail mais les CC et From ne fonctionnent pas les headers donc
    J"ai parcouru exemple et forum mais mon code semble correct
    Merci pour votre aide
    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
    <?php
    if(isset($_POST["submit"])){
    // Checking For Blank Fields..
    if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
    echo "Fill All Fields..";
    }else{
    // Check if the "Sender's Email" input field is filled out
    //$email=$_POST['vemail'];
     
    // Sanitize E-mail Address
    //$email =filter_var($email, FILTER_SANITIZE_EMAIL);
    // Validate E-mail Address
    //$email= filter_var($email, FILTER_VALIDATE_EMAIL);
    $email=htmlspecialchars($_POST["vemail"]);
    $message = htmlspecialchars($_POST["msg"]);
    if (!$email){
    echo "Invalid Sender's Email";
    }
    else{
    $subject = $_POST['sub'];
    $headers  = 'MIME-Version: 1.0'."\n"; // Version MIME
    $headers .= 'Reply-To: '.$email."\n";
    $headers .= 'From:'.$email. "\n"; // Sender's Email
    $headers .= 'Cc:'.$email. "\n"; // Carbon copy to Sender
    echo $headers;
    // Message lines should not exceed 70 characters (PHP rule), so wrap it
    $message = wordwrap($message, 70);
    // Send Mail By PHP Mail Function
    mail("moi@gmail.com",$subject,$message,$headers);
    echo "Your mail has been sent successfuly ! Thank you for your feedback";

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour et bienvenu sur DVP,



    sinon, utiliser phpMailer.

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2017
    Messages : 71
    Points : 50
    Points
    50
    Par défaut
    Merci pour votre réponse
    Je vais utiliser phpmailer
    A host je rajoute le serveur smtp de mon nom de domaine ?
    ça doit pas etre evident à trouver sur mon hebergeur
    Merci

  4. #4
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2017
    Messages : 71
    Points : 50
    Points
    50
    Par défaut
    Re ,

    j'ai finalement pas accés au serveur SMTP
    Je remets mon code si quelqu'un voit se qui cloche,merci
    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
     
    if(isset($_POST["submit"])){
    // Checking For Blank Fields..
    if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
    echo "Fill All Fields..";
    }else{
    // Check if the "Sender's Email" input field is filled out
    //$email=$_POST['vemail'];
     
     
    $email=htmlspecialchars($_POST["vemail"]);
     
    $message = htmlspecialchars($_POST["msg"]);
    if (!$email){
    echo "Invalid Sender's Email";
    }
    else{
     
    $subject = $_POST['sub'];
    $headers  = 'MIME-Version: 1.0'."\r\n"; // Version MIME
    $headers .= 'To: Demande <l@gmail.com>' . "\r\n";
    $headers .= 'From:'.$email. "\r\n"; // Sender's Email
    $headers .= 'Cc:'.$email. "\r\n"; // Carbon copy to Sender
     
    // Message lines should not exceed 70 characters (PHP rule), so wrap it
    $message = wordwrap($message, 70);
    // Send Mail By PHP Mail Function
    mail("l@gmail.com",$subject,$message,$headers);
     
    echo "Your mail has been sent successfuly ! Thank you for your feedback";
    }
    }
    }

  5. #5
    Invité
    Invité(e)
    Par défaut



    Tu peux l'utiliser sans SMTP :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <?php		// ---------------------
    		$mail = new PHPMailer;
    //		$mail->IsSMTP();  	// telling the class to use SMTP
    //		$mail->Host     		= '';
    //		$mail->SMTPAuth 	= false; // true - false : Enable SMTP authentication
    		$mail->IsMail();  	// => Sets Mailer to send message using PHP mail() function
    		// ......
    Ca fonctionne aussi.

  6. #6
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2017
    Messages : 71
    Points : 50
    Points
    50
    Par défaut
    Merci bien je tente ça

  7. #7
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2017
    Messages : 71
    Points : 50
    Points
    50
    Par défaut
    Re j'essaye avec phpmailer

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    $mail = new PHPMailer;
    	$mail->IsSMTP();  	// telling the class to use SMTP
    	$mail->Host = '';
    	$mail->SMTPAuth = false; // true - false : Enable SMTP authentication
    	$mail->IsMail();  	// => Sets Mailer to send message using PHP mail() function
    	$mail->AddAddress("l@gmail.com");
           $mail->Subject = "Test 1";
           $mail->Body = "Test 1 of PHPMailer.";
    et j'ai le message d'erreur suivant

    Fatal error: Uncaught Error: Call to undefined function split() in /storage/h9/151/1426151/public_html/PHPMailer-FE_v4.11/_lib/class.phpmailer.php:472 Stack trace: #0 /storage/h9/151/1426151/public_html/PHPMailer-FE_v4.11/_lib/class.phpmailer.php(415): PHPMailer->MailSend('Date: Wed, 26 A...', 'Test 1 of PHPMa...') #1 /storage/h9/151/1426151/public_html/contact.php(27): PHPMailer->Send() #2 /storage/h9/151/1426151/public_html/contact.php(34): smtpMailer('laurent.gevaert...', 'laugev73@gmail....', 'votreNom', 'Votre Message', 'Le sujet de vot...') #3 {main} thrown in /storage/h9/151/1426151/public_html/PHPMailer-FE_v4.11/_lib/class.phpmailer.php on line 472

    visible c'est la class elle même qui pose probleme

  8. #8
    Invité
    Invité(e)
    Par défaut
    Voir split().
    Avertissement

    Cette fonction est devenue OBSOLÈTE en PHP 5.3.0, et a été SUPPRIMÉE en PHP 7.0.0.
    donc si tu es en PHP7, ça ne va plus...

    Vérifie que tu as la dernière version de phpMailer.


    Et supprime ces lignes de ton code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    	$mail->IsSMTP();  	// telling the class to use SMTP
    	$mail->Host = '';
    	$mail->SMTPAuth = false; // true - false : Enable SMTP authentication
    Puisque tu utilises $mail->IsMail();.

  9. #9
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2017
    Messages : 71
    Points : 50
    Points
    50
    Par défaut
    effectivement split pose soucis
    J'e vais télécharger une version plus recente et je reviens merci pour ton aide
    J'ai pas fait de php depuis 10 ans...

  10. #10
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2017
    Messages : 71
    Points : 50
    Points
    50
    Par défaut
    C'est vraiment un truc de dingue Les CC ne passent pas comme avec la fonction mail de php
    Une limitation de mon hébergeur?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    $mail = new PHPMailer;
    	/*$mail->IsSMTP();  	// telling the class to use SMTP
    	$mail->Host = '';
    	$mail->SMTPAuth = false; // true - false : Enable SMTP authentication*/
    	$mail->IsMail();  	// => Sets Mailer to send message using PHP mail() function
    	$mail->AddAddress("laugev73@gmail.com","name");
    	$mail->AddCC('laugev73@gmail.com', 'Person One');
            $mail->Subject = "Test 1";
            $mail->Body = "Test 1 of PHPMailer.";

  11. #11
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2017
    Messages : 71
    Points : 50
    Points
    50
    Par défaut
    visiblement c'est ça
    Un bidouillage comme ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    if(!$mail->Send()) {
    		return 'Mail error: '.$mail->ErrorInfo;
    	} else {
     
     
    		$mail->AddAddress("laugev73@gmail.com","name");
    		return true;
    	}
    permet d'en envoyer deux à la fois
    Aprés dans un sens ça ne semble pas illogique dans la mesure ou si le mail a bien été envoyé on envoyé la confirmation
    Cependant est ce fiable?

  12. #12
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2017
    Messages : 71
    Points : 50
    Points
    50
    Par défaut
    Voila un code qui marche
    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
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    /**
     * This example shows settings to use when sending via Google's Gmail servers.
     */
    //SMTP needs accurate times, and the PHP time zone MUST be set
    //This should be done in your php.ini, but this is how to do it if you don't have access to that
    date_default_timezone_set('Etc/UTC');
    require 'PHPMailer-5.2.23/PHPMailerAutoload.php';
    //Create a new PHPMailer instance
    $mail = new PHPMailer;
    //Tell PHPMailer to use SMTP
    $mail->isSMTP();
    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 2;
    //Ask for HTML-friendly debug output
    $mail->Debugoutput = 'html';
    //Set the hostname of the mail server
    $mail->Host = 'smtp.gmail.com';
    // use
    // $mail->Host = gethostbyname('smtp.gmail.com');
    // if your network does not support SMTP over IPv6
    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
    $mail->Port = 587;
    //Set the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'tls';
    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;
    //Username to use for SMTP authentication - use full email address for gmail
    $mail->Username = "e@gmail.com";
    //Password to use for SMTP authentication
    $mail->Password = "******";
    $mail->SMTPSecure = 'tls';
    //Set who the message is to be sent from
    $mail->setFrom('e@gmail.com', 'First Last');
    //Set an alternative reply-to address
    $mail->addReplyTo(e@gmail.com', 'First Last');
    //Set who the message is to be sent to
    $mail->addAddress(e@gmail.com', 'John Doe');
    $mail->AddCC('xxxxxx@hotmail.fr', 'Person One');
    //Set the subject line
    $mail->Subject = 'PHPMailer GMail SMTP test';
    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
    //Replace the plain text body with one created manually
    $mail->Body = 'This is a plain-text message body';
    //Attach an image file
    //$mail->addAttachment('images/phpmailer_mini.png');
    //send the message, check for errors
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }
    Le probleme n'etait pas mon hebergeur mais les serveurs smtp distant dont il faut changer le niveau de sécurité sinon c'est consideré comme une attaque sur la boite mail ...
    Testé en local aussi sur wamp il faut modifier le fichier php ini a smtp
    votre smtp.com etc
    Classe PHP trés puissante et pratique!!!
    Merci pour ton aide et tes conseils

Discussions similaires

  1. probleme envoi mail avec php mail
    Par phter dans le forum Langage
    Réponses: 0
    Dernier message: 31/05/2012, 16h08
  2. probleme envoi mail
    Par popofpopof dans le forum VBA Access
    Réponses: 2
    Dernier message: 06/06/2007, 09h51
  3. [Automation]Probleme Envoi Mail
    Par Clemiou dans le forum VBA Access
    Réponses: 7
    Dernier message: 20/04/2007, 17h15
  4. [Mail] probleme envoie mail
    Par phoeniix07 dans le forum Langage
    Réponses: 7
    Dernier message: 21/06/2006, 14h35
  5. [Mail] Envoie mail PHP
    Par oldscrout dans le forum Langage
    Réponses: 4
    Dernier message: 29/03/2006, 14h55

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