• 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.

2.3k points
reopened by

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
selected by

Related questions

0 votes
1 answer 46 views
Problem: I need someone&rsquo;s help to fix it
asked Mar 12 Ifra 43.4k points
0 votes
1 answer 20 views
Problem: Please solve it &hellip; Because I am unable to find out the solution
asked Mar 12 Ifra 43.4k points
1 vote
2 answers 1.4k views
i want to add some string to the url in ajax process, but fail every time i access the function. when i submit the form it only access this url 'Master_data/' var jenis_submit = document.getElementById('jenis_submit'); var submit_url = ''; if(jenis_submit == '1'){ ... contentType: false, cache: false, processData: false, success:function(data){ // console.log(data); $('#notif').html(data); } }
asked May 27, 2019 sadmin 2.3k points
0 votes
1 answer 21 views
Problem: Hello ... Can anyone tell me that why I got this error?
asked Mar 12 Ifra 43.4k points
1 vote
1 answer 22 views
Problem: Getting the following error. Mailer error could not instantiate mail function.
asked Mar 25 PkGuy 25.9k points
0 votes
1 answer 119 views
Problem Hi Kodlogs, How am having following error while sending mails using PHP: mailer error: could not instantiate mail function Need help fixing please
asked Nov 3, 2020 hashq 1.1k points
1 vote
1 answer 25 views
Problem: My site is using PHP mail() function to send emails Due to any reason if the mail doesn&rsquo;t send , then I want it to show an error message . Something like $this_mail = mail('*Emails are not allowed*', 'My Subject', $message); if($this_mail) echo 'sent!'; else echo error_message; How can I do this ?
asked Apr 5 Raj Tyagi 16k points
0 votes
1 answer 78 views
I need to know how i can display hyperlinks without an underline.
asked Oct 5, 2020 Daniel Anderson 4k points
0 votes
1 answer 3 views
Problem: Could not instantiate mail function. joomla.
asked Jul 10 Rada Gracelynn 104k points
0 votes
1 answer 19 views
Problem: Can anyone help me out please : Mail:could not instantiate mail function?
asked Jun 1 Irenka Kiri 85.5k points