0

Hey I am trying to create forget password feature. When a user forget the login password an email address must be send to his/her email with a password reset link. I wonder how to do so?

I have the user password stored in the database I can retrive it easily. I just do no know how to create a program that is able to send email to all email address. As far as now, I only able to send email to gmail.

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = smtp.gmail.com
smtp_port = 587
;smtp_port = 465

contact.php

    <!DOCTYPE html>
    <html lang="en">

        <head>

            <!-- Basic -->
            <meta charset="utf-8">
            <title>SquPrime - Learn Mandarin with Native teachers directly from China</title>
            <meta name="author" content="DSA79">
            <meta name="norobots" content="noindex,nofollow">
            <meta name="keywords" content="responsive, html5 template, one page, landing, startup, business, company, corporate, creative">
            <meta name="description" content="We provide certificated online Mandarin courses. Private and group lessons are available. Request a free trial now!">      

            <!-- Libs CSS -->
            <link href="css/style.css" rel="stylesheet" type="text/css" />
            <link href="css/bootstrap.css" rel="stylesheet" type="text/css" />

            <link href="css/green.css" rel="stylesheet">   
            <link href="css/darkorchid.css" rel="stylesheet">     
            <link href="css/darkred.css" rel="stylesheet"> 
            <link href="css/darkblue.css" rel="stylesheet"> 
            <link href="css/wheat.css" rel="stylesheet">         
            <link href="css/turquoise.css" rel="stylesheet">  
            <link href="css/lightgreen.css" rel="stylesheet">     
            <link href="css/honeydew.css" rel="stylesheet">
            <link href="css/darkpink.css" rel="stylesheet">

            <!-- Google Fonts -->    
            <link href='http://fonts.googleapis.com/css?family=Raleway:400,100,200,300,500,600,700,800,900' rel='stylesheet' type='text/css'>

        </head>

        <body>

    <?php

    $stu_fname = isset($_POST['stu_fname']) ? $_POST['stu_fname'] : '';
    $stu_email = isset($_POST['stu_email']) ? $_POST['stu_email'] : '';
    $stu_telp = isset($_POST['stu_telp']) ? $_POST['stu_telp'] : '';

    include('includes/koneksi.php');


                if (isset($_POST['register'])){


                if(!empty($stu_fname) && !empty($stu_email) && !empty($stu_telp)){

                $sqlstr = "INSERT INTO student(stu_fname, stu_email, stu_telp) VALUES('".$stu_fname."','".$stu_email."','".$stu_telp."')";

                $result = mysql_query($sqlstr) or die(mysql_error());

                $result2 = mysql_query("SELECT student_id FROM student ORDER BY student_id DESC");

                $dataSID = mysql_fetch_array($result2);

                //header("location:registration2.php?student_id='".$dataSID['student_id']."'");
                } 
                else
                {           
                $error = "<i>Please fill-in all fields information in this form.</i><br>";

                $result = "";
                }

                //Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
                //if (empty($_REQUEST['id']))   kirimEmail($idKategori, $judul, $news);
                $confirmation = ($result) ? "Data has been saved." : "Fail to save data.";  

            }   


    // PHP Mailer 

    require 'C:/xampp/htdocs/phpmailer/PHPMailerAutoload.php';
     //memanggil library php mailernya


    function smtpmailer($to, $from, $from_name, $subject, $body) {

    global $error;

    $mail = new PHPMailer();

    //$mail->AuthType = 'NTLM';

    $mail->IsSMTP();

    //$mail->SMTPDebug = 0;  // untuk memunculkan pesan error /debug di layar

    $mail->SMTPAuth = true;  // authentifikasi smtp enable atau disable

    $mail->SMTPSecure = "";//‘ssl atau di kosongkas jika none’; // secure transfer membutuhkan authentifikasi dari mail server

    $mail->Host ='ssl://smtp.gmail.com:465;tls://smtp.gmail.com:587'; // masukkan nama host email “diawal ssl://”

    $mail->Port = 587; //port secure ssl email

    $mail->Username = "squprime@gmail.com"; //username email

    $mail->Password = "********"; //password email

    $mail->SetFrom($from, $from_name);

    $mail->Subject = $subject;

    $mail->Body = $body;

    $mail->AddAddress($to);

    if(!$mail->Send()) {

    $error = "Mail error: ".$mail->ErrorInfo;

    return false;

    } else {

    $error = "Message sent!";

    return true;

    }

    }


        $result = mysql_query("SELECT * FROM student ORDER BY student_id DESC") or die(mysql_error());
        $data = mysql_fetch_array($result);


    // write program to send email to the recorded email address


        $name = $data['stu_fname'];
        $email = $data['stu_email'];
        $phone = $data['stu_telp'];
        $message = "Dear Admin,"."\r\r".
        "There is a new user registration";

        /*if (@$_POST['submit']) {*/
        if ($name&&$email&&$phone&&$message) {
        if (is_numeric($phone)) {

        $body = "
        Name: ".$name."
        Phone: ".$phone."
        Email: ".$email."\n\n
        ".$message;

        smtpmailer("squprime@gmail.com", "squprime@gmail.com", "Davy", "Test Email", $body); 
        //smtpmailer("squprime@indonusa.net.id", "squprime@indonusa.net.id", "Davy", "Test Email", $body); // script kirim email

        echo "Your message has been sent, we will get back to your shortly.";
        $name = trim("");
        $email = trim("");
        $phone = trim("");
        $message = trim("");
        }
        else
        echo "There should only be numbers in your phone number.";
        } 
        else
        echo "Please fill in <b>all</b> the fields!";


    ?>  





            <div id="contentForm">

                <?php
                header('Content-Type: text/html; charset=utf-8');

                if(isset($_POST['email'])) {


                    // EDIT THE 2 LINES BELOW AS REQUIRED

                    //$email_to = "cs@squprime.com";
                    $email_to = "squprime@gmail.com";

                    $email_subject = "SquPrime Free trial request!";


                    $first_name = $_POST['first_name']; // required 
                    $email_from = $_POST['email']; // required
                    $phone = $_POST['phone']; // required

                    $email_message = "Form details below.\n\n";


                    function clean_string($string) {
                        $bad = array("content-type","bcc:","to:","cc:","href");
                        return str_replace($bad,"",$string);
                    }


                    $email_message .= "Name: ".clean_string($first_name)."\n";
                    $email_message .= "Email Address: ".clean_string($email_from)."\n";
                    $email_message .= "Phone Number: ".clean_string($phone)."\n";


                    // create email headers

                    $headers = 'From: '.$email_from."\r\n".

                    'Reply-To: '.$email_from."\r\n" .

                    'X-Mailer: PHP/' . phpversion();

                    //@mail($email_to, $email_subject, $email_message, $headers);

                    //$ok = @mail($email_to, $email_subject, $email_message, $headers);

                    $ok = mail("squprime@gmail.com", "Subject", "This is the email message", "From me");

                    if($ok){ echo "successfully sent message"; } else { echo "failed to send message"; }
                    ?>

                    <!-- Message sent! (change the text below as you wish)-->
                    <div class="container">
                        <div class="row">
                            <div class="col-sm-6 col-sm-offset-3">
                                <div id="form_response" class="text-center">
                                    <img class="img-responsive" src="img/thumbs/mail_sent.png" alt="image" />
                                    <h1>Your request is sent!</h1>
                                    <p>Thank you <b><?=$first_name;?></b>, our advisor will contact you within 24 hours!</p>
                                    <a class="btn btn-theme btn-lg" href="index.php">Back To The Site</a>
                                </div>
                            </div>   
                        </div>                   
                    </div>
                     <!--End Message Sent-->

                    <?php

                    }

                    ?>

            </div>

        </body>

    </html>
3
Contributors
4
Replies
46
Views
2 Years
Discussion Span
Last Post by davy_yg
0

Your Google SMTP account can send email to any address - if you are able to send email to yourself on Google without getting any warning bars at the top of the email view, it will work with any other email address as well. If you do get any of Google's yellow warning bars about the email not being from who it says it is from, or other errors. Post those and maybe we can help figure out what is wrong.

0

Looks like you are working on your local computer. This is why you need php smpt mailer.. If you are on a live web server with sendmail instalaled you can use php mail() function to send email's without using your google account

Example:

$from = 'no-reply@domain.dev'; // sender
$to = 'someone@domain.dev';
$subject = 'Password Reset';
$message = 'password';

if(mail($to,$subject,$message,"From: $from\n")){
echo "Thank you for sending us feedback";
}

You can read more here: Click Here

0

I thought it suppose to work also with PHPMailer - I am using a web server (I upload all my files there).

0

I try this:

sendpassword.php

<?php


    $email = $_POST['email'];

    $from = 'no-reply@domain.dev'; // sender
    $to = 'squprime@indonusa.net.id';
    $subject = 'Password Reset';
    $message = 'password';
    if(mail($to,$subject,$message,"From: $from\n")){
    echo "Thank you for sending us feedback";
    }


?>  

php.ini

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = smtp.gmail.com
smtp_port = 587
;smtp_port = 465

I check my email and still have not receive any email message.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.