• Register
1 vote

I'm building an Email verification script and i'm using ajax so whenever the user fill in a false or an invalid email, an error bar with the error name will be displayed, And when the email is true and belongs to an active account, an email will be sent to the user with instructions and the error bar says email sent. The problem is even the mail function isn't working, the error bar keeps saying email sent. So i wan't some lines to detect if the email wasn't sent to show "email was not sent" in the error bar.

13 9 6
2,200 points

Please log in or register to answer this question.

1 Answer

1 vote
Best answer

My php file :


include '../../app/init.php';

        /* Clean email */
    $recover_email = $_POST['recover_email'];

       /* check if email is valid */
    if(!filter_var($recover_email, FILTER_VALIDATE_EMAIL)) {

        /* email not valid */
        echo 3;

        /* Check if email exist */
    } else if(Database::exists('user_id', 'users', ['email' => $recover_email])) {

        /* Define some variables */
        $user_id            = Database::simple_get('user_id', 'users', ['email' => $recover_email]);
        $lost_password_code = md5($recover_email + microtime());

        /* Update the current activation email */
        $database->query("UPDATE `users` SET `lost_password_code` = '{$lost_password_code}' WHERE `user_id` = {$user_id}");

$mail->send() is used to send mail. You don't need to call `send_mail($to, $from, $title, $message);` inside if condition. Use the following if (!$mail->send()) { // write error message }

/* Send the email */ sendmail($recover_email, $settings->contact_email, $language->lost_password->email->title, sprintf($language->lost_password->email->content, $settings->url, $recover_email, $lost_password_code)); /* email exist */ echo true; } else if(!Database::exists('user_id', 'users', ['email' => $email])) { /* email not exist */ echo false; } ?>

540 points

Related questions

0 votes
1 answer 48 views
0 votes
1 answer 5 views
Problem: I need someone&rsquo;s help to fix it
asked Mar 12 Ifra 24.4k points
0 votes
1 answer 4 views
Problem: Please solve it &hellip; Because I am unable to find out the solution
asked Mar 12 Ifra 24.4k points
0 votes
1 answer 145 views
I am finding difficulty with following issue, any help appreciated: java.sql.sqlexception: can not issue data manipulation statements with executequery().
asked Jul 25, 2020 James Martin 2.2k points
0 votes
1 answer 20 views
0 votes
1 answer 13 views