• Register
1 vote
153 views

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 3
2,100 points

1 Answer

1 vote
 
Best answer

My php file :

    <?php 

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; } ?>

1
540 points

Related questions

0 votes
1 answer 24 views
24 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 James Martin 2.2k points