Jump to content

[SOLVED] php mail goes to inbox as a .dat file


jesushax

Recommended Posts

Few more detail please...

 

The "mail" you try to sent get's attached as a .dat. What about the mail to which the .dat is attached? What topic does it have, what is in it's body and what does the .dat contain?

 

My guess (and it is only a guess, I don't know much about mail servers) is that the e-mail you sent is somehow faulty / incorrect and the server corrects this by attaching your faulty e-mail message to a correct formatted e-mail message...

 

The code might be helpful too :)

Link to comment
Share on other sites

heres the full page code

 

<?php include($_SERVER['DOCUMENT_ROOT'] . '/new/includes/connection.php');
session_start();
include($_SERVER['DOCUMENT_ROOT'] . '/new/includes/header.php');

function ShowForm() {
?>
<form name="lostpass" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?action=lostpass">
<p style="padding:2px 0;">
Your Email Address :
<input name="txtEmailAddress" type="text" size="30"></p> 
<p style="text-align:center;"><input name="" type="submit" value="Reset My Password"></p>

</form>
<p style="padding:2px 0; text-align:center;">
<a href="/new/admin/index.php">Back To Login Form</a>
</p>
<?php
}

function createRandomPassword() {

    $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double)microtime()*1000000);
    $i = 0;
    $pass = '' ;

    while ($i <= 7) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $pass = $pass . $tmp;
        $i++;
    }
    return $pass;
}

switch(@$_GET["action"]) {
Case "noemail":
echo "<h3>Lost Password</h3>";
echo '<span style="font-weight:bold; color:#FF0000;">Error: The email address you provided does not exist.</span>';
ShowForm();
break;

Case "lostpass":
ini_set ("smtp.karoo.co.uk","*******");
ini_set ("sendmail_from","********");

echo "<h3>Lost Password</h3>";
$Email =  $_POST["txtEmailAddress"];

$sql = mysql_query("SELECT * FROM tblAdmin WHERE UserEmail='$Email' ") or die(mysql_error());

$rspass = mysql_fetch_array($sql);

if(mysql_num_rows($sql) < 1){
header("Location: ".$_SERVER['PHP_SELF']."?action=noemail"); //address doesnt exist
}
else{
$ID = $rspass["UserID"];
$Username = $rspass["UserName"];

// creat password
$password = createRandomPassword();

$Newpass = md5($password);

mysql_query("UPDATE tblAdmin SET UserPassword='$Newpass' WHERE UserID='$ID'") or die(mysql_error());

$to = "$Email";
$subject = ": Your New Password";
$message = "
<html>
<head>
<title>Reset Password</title>
</head>
<body>
<p>
Your password for   Has been reset to the following</p>
<p>Your Username is: $Username</p>
<p>Your New Password is: $password</p>
<p>To change your password please login and go to the My Details section of the site and change your password there.<br/>
</p>
</body>
</html>
";// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";// More headers

mail($to,$subject,$message,$headers);
header("Location: /new/admin/index.php?action=sent");
}
break;
default:
echo "<h3>Lost Password</h3>";
ShowForm();
break;
}
include($_SERVER['DOCUMENT_ROOT'] . '/new/includes/footer.php');
s
?>

 

and

 

the .dat file has this info in

 

 

<html>

<head>

<title>Reset Password</title>

</head>

<body>

<p>

Your password for has been reset to the following</p>

<p>Your Username is: Alex</p>

<p>Your New Password is: d4r04krb</p>

<p>To change your password please login and go to the My Details section of the site and change your password there.<br/>

</p>

</body>

</html>

 

thanks

Link to comment
Share on other sites

I'm not sure what I ask will help solve your problem, but I would like to know topic, body and headers (if you have them from your e-mail client) of the e-mail message containing the .dat attachment....

Link to comment
Share on other sites

not sure if i get what yoru after here, but the email that is recieved is

 

From: info@domain.com

 

Subject: Your New password - as stated in the code

 

and the body

 

theres isnt one, the bosy is in the .dat attchement

 

Cheers

Link to comment
Share on other sites

If I were to debug the script I would cut to the bare bones and then start filling on until this strange behavior starts appearing...

 

Start out with this and get that to work:

 

<?php

$to = "$Email";
$subject = ": Your New Password";
$message = "
<html>
<head>
<title>Reset Password</title>
</head>
<body>
<p>
Your password for   Has been reset to the following</p>
<p>Your Username is: $Username</p>
<p>Your New Password is: $password</p>
<p>To change your password please login and go to the My Details section of the site and change your password there.<br/>
</p>
</body>
</html>
";// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";// More headers

mail($to,$subject,$message,$headers);

?>

Link to comment
Share on other sites

i just craeted a test page to send an email and unless i define the from address i get a php error

 

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Websites\*****\test.php on line 23

 

so ehres the code i used, therse not problem with the code here

 

<?php 
$to = "alex@mydomain.com";
$subject = ": Your New Password";
$message = "
<html>
<head>
<title>Reset Password</title>
</head>
<body>
<p>
Your password for   Has been reset to the following</p>
<p>Your Username is: Username</p>
<p>Your New Password is: password</p>
<p>To change your password please login and go to the My Details section of the site and change your password there.<br/>
</p>
</body>
</html>
";// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <info@mydomain.com>' . "\r\n";

mail($to,$subject,$message,$headers);
?>

 

i think its the php.ini file need setting, would anybody know what settings id need to tell my domain host to do?

 

Thanks

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.