mamaomphile Posted February 25, 2014 Share Posted February 25, 2014 (edited) <form action="forgotPsw.php" method="post"> Enter you Email Address: <input type="text" name="email"> <input type="submit" name="submit" value="Send"> </form> With this code am trying to send an email using mail function, which is not doing that and with no errors displaying, so i cant really figure out what is the problem since its updating the database giving the write echo statements but the email is not going through? please assist me <?php error_reporting(0); $email=$_POST['email']; if($_POST['submit']=='Send') { require_once "my database"; mysql_connect($svr, $dba, $pwd) or die(mysql_error); mysql_select_db($dbt); $query="select * from users where Email='$email'"; $result=mysql_query($query) or die(error); // checks if the username is in use if(mysql_num_rows($result)){ echo "User exist ----"; }else{ echo "No user exist with this email address----"; } if(mysql_num_rows($result)){ //$code=rand(100,999); //$message="You activation link is: http://10.10.200.250/cmsintranet/forgotPsw.php?email=$email&code=$code"; //mail($email, "Activation link", $message); //send email $mail->Mailer = "smtp"; $mail->Host = "my host"; $mail->Port = 25; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "i used an email address"; // SMTP username $mail->Password = "psw to the email"; // SMTP password //create a new random password $password = substr(md5(uniqid(rand(),1)),3,10); $pass = md5($password); //encrypted version for database entry $to = "$email"; $subject = "Account Details Recovery"; $body = "Hi $r->username, nn you or someone else have requested your account details. nn Here is your account information please keep this as you may need this at a later stage. nnYour username is $r->username nn your password is $password nn Your password has been reset please login and change your password to something more rememberable.nn Regards Site Admin"; $additionalheaders = "From: <email.......>rn"; mail($to, $subject, $body, $additionalheaders); //update database $sql = mysql_query("UPDATE users SET u_password='$pass' WHERE Email = '$email'")or die (mysql_error()); $rsent = true; //show any errors if (!empty($error)){ $i = 0; while ($i < count($error)){ //echo "<div class="msg-error">".$error[$i]."</div>"; $i ++; } } if ($rsent == true){ echo "<p>You have been sent an email with your account details to $email</p>"; } else { echo "<p>Please enter your e-mail address. You will receive a new password via e-mail.</p>"; } //echo "Email sent"; }else{ echo "Email not sent"; } } ?> Edited February 25, 2014 by mamaomphile Quote Link to comment https://forums.phpfreaks.com/topic/286513-mail-function-not-working/ Share on other sites More sharing options...
jazzman1 Posted February 25, 2014 Share Posted February 25, 2014 Why do you want to mix up a mail library such as phpmailer with a core sendmail? Quote Link to comment https://forums.phpfreaks.com/topic/286513-mail-function-not-working/#findComment-1470591 Share on other sites More sharing options...
mamaomphile Posted February 25, 2014 Author Share Posted February 25, 2014 Because i have been trying everything and still not winning when i decided to come up with the coding above, my simple code was: <form action="forgotPsw.php" method="post">Enter you Email Address: <input type="text" name="email"><input type="submit" name="submit" value="Send"></form> <?phperror_reporting(0);$email=$_POST['email'];if($_POST['submit']=='Send'){require_once "dba/dba.php";mysql_connect($svr, $dba, $pwd) or die(mysql_error);mysql_select_db($dbt);$query="select * from usertest where user_email='$email'";$result=mysql_query($query) or die(error); if(mysql_num_rows($result)){ echo "User exist ----"; }else{ echo "No user exist with this email address----"; } if(mysql_num_rows($result)){ $code=rand(100,999); $message="You activation link is: http://10.10.200.250/cmsintranet/forgotPsw.php?email=$email&code=$code"; mail($email, "Subject Goes Here", $message); echo "Email sent"; }else{ echo "Email not sent"; } }?> but still not working Quote Link to comment https://forums.phpfreaks.com/topic/286513-mail-function-not-working/#findComment-1470592 Share on other sites More sharing options...
jazzman1 Posted February 25, 2014 Share Posted February 25, 2014 What environment are you on, Unix or Windows? Quote Link to comment https://forums.phpfreaks.com/topic/286513-mail-function-not-working/#findComment-1470598 Share on other sites More sharing options...
mamaomphile Posted February 25, 2014 Author Share Posted February 25, 2014 windows! Quote Link to comment https://forums.phpfreaks.com/topic/286513-mail-function-not-working/#findComment-1470604 Share on other sites More sharing options...
EffakT Posted February 25, 2014 Share Posted February 25, 2014 Is this returning any errors? are you running XAMPP? Quote Link to comment https://forums.phpfreaks.com/topic/286513-mail-function-not-working/#findComment-1470662 Share on other sites More sharing options...
jazzman1 Posted February 26, 2014 Share Posted February 26, 2014 (edited) Afaik from the windows users coming here and using a php mail function, the easiest way is to set up a remote connection between your local machine and some external mail server as gmail, yahoo, so on. Because to send or receive emails you need to have a mail server with mail account itself. By default the windows system ( when I used to actively it was about more than 13 years) didn't come with a copy of mail server software inbuilt itself, but time has been changed. The best way is to check docs of your windows version. Edited February 26, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/286513-mail-function-not-working/#findComment-1470710 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.