Visualizzazione risultati 1 fino 6 di 6

Discussione: Errore invio email

  1. #1
    esperatempo non è connesso Utente Blog
    Data registrazione
    28-11-2021
    Messaggi
    24

    Predefinito Errore invio email

    Ciao a tutti,

    sul mio sito ho implementato un sistema di gestione utenti, che consente la registrazione al sito tramite compilazione di un modulo, inoltrato il quale, viene inviata una mail all'utente per confermare la registrazione. Usando PHP, Yii2 e SwiftMailer, il codice del metodo actionRegister() della classe UserController è questo qua sotto:

    Codice PHP:
    /**
    * UserController class for users to register, login, logout
    */
    class UserController extends \yii\web\Controller
    {
    /**
    * Display the register page.
    */
    public function actionRegister()
    {
    $user = new User(['scenario' => User::SCENARIO_REGISTER]);

    /**
    * If the action is called from within the register form (views/user/register.php), the form data are loaded into the $user variable
    * (using the load() method of the yii\base\Model class) and the validate() method is executed, in order to validate the user data.
    * If both action succeed, a password hash, an authorization key and a user token are created and the user data are stored.
    */
    if ($user->load(Yii::$app->request->post()))
    {
    /**
    * The submitted password is used to generate a password hash, which is stored into the user $hash field and will be later used
    * to validate the user login. An authorization key is also create, which is internally used for validating the login.
    */
    $user->hash = Yii::$app->security->generatePasswordHash($user->password);
    $user->auth_key = Yii::$app->security->generateRandomString();

    /**
    * Create a new token to add to the link to be sent to the user to call the "Confirm" action,
    * where will be checked if the sent token matches the user token.
    */
    $user->token = Yii::$app->security->generateRandomString();

    /**
    * Save the user into the database.
    */
    if ($user->save())
    {
    try
    {
    /**
    * Send the user a confirmation email for registering.
    */
    if (UserMailer::sendVerify($user))
    {
    /**
    * Notify the system administrator that the confirmation email has been sent.
    */
    UserMailer::verifySuccess($user);
    return
    $this->render('register/success', ['user' => $user, 'module' => $this->module->id]);
    }

    /**
    * If the confirmation email has not been sent...
    */
    else
    {
    /**
    * Notify the system administrator an error by sending the confirmation email.
    */
    UserMailer::verifyFailure($user, Module::t('default', 'Confirmation email not sent!'));

    return
    $this->render('register/failure',
    [
    'user' => $user,
    'error' => Module::t('default', 'Confirmation email not sent!')
    ]);
    }
    }

    catch (
    Swift_SwiftException $error)
    {
    /**
    * Notify the system administrator an error by sending the confirmation email.
    */
    UserMailer::verifyFailure($user, Module::t('default', 'Confirmation email error!'));

    return
    $this->render('register/failure',
    [
    'user' => $user,
    'error' => Module::t('default', 'Confirmation email error!')
    ]);
    }
    }

    /**
    * If the user data have not been saved...
    */
    else
    {
    /**
    * Notify the system administrator an error by saving the user data.
    */
    UserMailer::verifyFailure($user, Module::t('default', 'Data saving error!'));

    return
    $this->render('register/failure',
    [
    'user' => $user,
    'error' => Module::t('default', 'Data saving error!')
    ]);
    }
    }

    /**
    * Otherwise (if the action is called from a link), the register form is showed.
    */
    return $this->render('register/register', ['user' => $user]);
    }
    }
    Il problema è che a volte alcuni utenti hanno effettuato la registrazione, ma non hanno ricevuto la mail di conferma e non hanno ricevuto alcun messaggio di errore, e io non ho ricevuto alcuna notifica di errore. Ma questo a volte accade e a volte no, per cui non so spiegarmi assolutamente il motivo. Il codice if ($user->save()) viene sempre eseguito, perché i dati dell'utente vengono sempre registrati nel database, ma a volte non riceve appunto alcuna mail di conferma. Qualche idea?

    Grazie

  2. #2
    frasidipace non è connesso AlterGuru
    Data registrazione
    07-05-2010
    Messaggi
    2,369

    Predefinito

    Salve,
    alcuni provider di posta elettronica, in particolar modo Gmail, blocca le email se inviate da un modulo di contatto o di registrazione se l'email del mittente non è del relativo dominio.
    Con dominio di terzo livello potrebbe provare ad inviare le mail mediante alias Altervista, ma non è scontato che funzioni. Da Altervista, inoltre, non è possibile utilizzare server SMTP perche le porte sono bloccate per motivi di sicurezza.
    Se vuole andare sul sicuro si appoggi a servizi esterni come Sendgrid o Brevo (ex Sendinblue).

    Saluti

  3. #3
    esperatempo non è connesso Utente Blog
    Data registrazione
    28-11-2021
    Messaggi
    24

    Predefinito

    Citazione Originalmente inviato da frasidipace Visualizza messaggio
    Salve,
    Con dominio di terzo livello potrebbe provare ad inviare le mail mediante alias Altervista
    Sì, l'indirizzo del mittente è quello di altervista.

    Citazione Originalmente inviato da frasidipace Visualizza messaggio
    Salve,
    Se vuole andare sul sicuro si appoggi a servizi esterni come Sendgrid o Brevo (ex Sendinblue).
    Bene, do un'occhiata.

    Grazie

  4. #4
    esperatempo non è connesso Utente Blog
    Data registrazione
    28-11-2021
    Messaggi
    24

    Predefinito

    Citazione Originalmente inviato da frasidipace Visualizza messaggio
    Se vuole andare sul sicuro si appoggi a servizi esterni come Sendgrid o Brevo (ex Sendinblue).
    Ho guardato Brevo, ma mi chiede un sacco di dati sulla mia azienda, che non ho. Come procedere?

  5. #5
    frasidipace non è connesso AlterGuru
    Data registrazione
    07-05-2010
    Messaggi
    2,369

    Predefinito

    Citazione Originalmente inviato da esperatempo Visualizza messaggio
    Ho guardato Brevo, ma mi chiede un sacco di dati sulla mia azienda, che non ho. Come procedere?
    Sì, fa riferimento all'azienda, ma non mi sembra chieda dati fiscali.
    Almeno era così quando era ancora Sendinblue.
    I dati aziendali dovrebbero essere necessari ai fini di campagne di marketing.
    Eventualmente contatti il loro supporto.

    Saluti
    Ultima modifica di frasidipace : 03-09-2023 alle ore 12.09.12

  6. #6
    esperatempo non è connesso Utente Blog
    Data registrazione
    28-11-2021
    Messaggi
    24

    Predefinito

    Citazione Originalmente inviato da frasidipace Visualizza messaggio
    Eventualmente contatti il loro supporto.
    Bene, gli ho scritto, vediamo cosa rispondono.

    Grazie

Tags for this Thread

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •