• Register
search
Log In
1 vote
142 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.

2.1k points
reopened by

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

540 points
selected by

Related questions

1 vote
2 answers 270 views
270 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.1k points
0 votes
2 answers 120 views
120 views
Problem : Getting following wordpress error while tring to send the email the email could not be sent. possible reason: your host may have disabled the mail() function.
asked Nov 13, 2019 peterlaw 6.9k points
1 vote
1 answer 23 views
23 views
Problem : I have recently developed one page which I guess takes more time to load in the asp.net website. My page currently works with all the Android OS, all of the MAC OS and all iOS but it fails with iOS with version 10.0.0.2 with only safari browser. If I ... the DNS server Tried the Airplane mode on-off Also did my iPhone restart But still unable to fix it. Can someone help me in fixing it?
asked Apr 1 morrisBson 3.2k points
0 votes
1 answer 72 views
72 views
Problem : I am facing below error message Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in I am unable to understand this message. Please let me know how can I fix it?
asked Jan 31 jwilliam 3.9k points
0 votes
1 answer 111 views
111 views
Problem : I want to send mails using my web application. But my below code is showing me the below error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send ... false; mysmtp.Timeout = 600000; } // Passing values to smtp object mysmtp.Send(myfromAddress, mytoAddress, mysubject, mybody); } } }
asked Dec 9, 2019 alecxe 7.5k points