I have an issue with this code (it's not mine but I have to work on). It's for send a mail confirmation for an inscription. But the mail is not send with that.. Someone can help me ? Thank's a lot !

<?php
    class Users extends Model{
        var $table="users";

        function exist($d){
            $existM = $this->find(array("conditions"=>'email="'.$d['email'].'"'));
            $existL = $this->find(array("conditions"=>'login="'.$d['login'].'"'));
            if($existM || $existL){
                return true;
            }else{
                return false;
            }
        }
        function mail($data){
            //ini_set('memory_limit', '1024M');
            //ini_set("SMTP","smtp.sfr.fr");
            $destinataire = $data['email'];
            $sujet = "Activer votre compte";

            $entete = "From : Site personnel \n";
            $entete .= "MIME-version: 1.0\n";
            $entete .= "Content-type: text/html; charset= utf8\n";
            $msg='<h1>Bonjour "'.$data['login'].'" ! </h1>
                 <p>Pour activer votre compte, veuillez cliquer ici</p>
                 <p><a href="http://www.sylvain-blondin.com/activer?token='.$data['token'].'-'.$data['email'].'">Activer</a></p>';

            $sentmail = mail($destinataire, $sujet, $msg, $entete);

            if ($sentmail){
            echo $this->message("Pour finaliser votre inscription, un mail vous a été envoyé pour activer votre compte.","");
            } else{
            echo $this->message("Mail non envoyé","");
            }
        }

    }

?>

and where I set $data

<?php
extract($_POST);
$users = Model::load('Users');
$form = Model::load('Form');
if(isset($_FILES['avatar']) && $_FILES['avatar']['size']>0){
    $format = substr($_FILES['avatar']['type'],6,3);
    $format_auto = array("gif","png","jpg","jpe");
    if(in_array($format, $format_auto)){
        $data['avatar'] = $_FILES['avatar']['name'];
        $tmp_name = $_FILES["avatar"]["tmp_name"];
        $name = $data["avatar"];
        move_uploaded_file($tmp_name,"theme/images/avatar/$name");
    }else{
        echo $users->message("Le format de l'image n'est autorisé","error");
    }
}
if(isset($data['login']) && isset($data['password']) && isset($data['password2']) && isset($data['email'])){
    if(!empty($data['login']) && !empty($data['password']) && !empty($data['password2']) && !empty($data['email'])){
        if($data['password']!=$data['password2']){
            $erreur = array('password2' => 'Les mots de passe ne sont pas identiques');
            $form->setErrors($erreur);
        }else{

            if(!$users->exist($data)){
                unset($data['password2']);
                $data['password'] = sha1($data['password']);
                $data['token'] = md5(rand());
                $users->save($data);
                $users->mail($data);

            }else{
                echo $users->message("Le login ou l'email est déja utilisé","error");
            }      
        }
    }
    else{
        echo $users->message("Vous n'avez pas rempli tous les champs","error");
    }
}
?>
有帮助吗?

解决方案

It's resolved (or at least arounded the problem) I remove the tag in $msg, and I let it as a simple String. The mail is sent !

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top