Jump to content

mail function not working


mamaomphile

Recommended Posts


<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 by mamaomphile
Link to comment
Share on other sites

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>

 

<?php
error_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

Link to comment
Share on other sites

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 by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.