jesushax Posted July 14, 2008 Share Posted July 14, 2008 Hi could anyone tell me why a php html mail script would be sent as a .dat attachment? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/ Share on other sites More sharing options...
Wuhtzu Posted July 14, 2008 Share Posted July 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-589434 Share on other sites More sharing options...
jesushax Posted July 14, 2008 Author Share Posted July 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-589457 Share on other sites More sharing options...
Wuhtzu Posted July 14, 2008 Share Posted July 14, 2008 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.... Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-589479 Share on other sites More sharing options...
jesushax Posted July 14, 2008 Author Share Posted July 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-589502 Share on other sites More sharing options...
jesushax Posted July 14, 2008 Author Share Posted July 14, 2008 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-589661 Share on other sites More sharing options...
Wuhtzu Posted July 14, 2008 Share Posted July 14, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-589992 Share on other sites More sharing options...
jesushax Posted July 15, 2008 Author Share Posted July 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590278 Share on other sites More sharing options...
DeanWhitehouse Posted July 15, 2008 Share Posted July 15, 2008 u could try using phpmailer Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590283 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 What is the name of the .dat file winmail.dat? Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590286 Share on other sites More sharing options...
jesushax Posted July 15, 2008 Author Share Posted July 15, 2008 the name of the .dat file is the subject of the email _Your New Password.dat Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590287 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 Hi jesushax, That code works perfectly on my machine. Is .dat file being attached in your outlook client or are you using any webmail like hotmail, yahoo, if not, try using a webmail so we can pinpoint the issue. Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590289 Share on other sites More sharing options...
jesushax Posted July 15, 2008 Author Share Posted July 15, 2008 hi yeah sending to a hotmail account works fine to outlook via exchange server it comes as a .dat Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590316 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 then...i think its something got to do with your outlook configuration ... Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590318 Share on other sites More sharing options...
jesushax Posted July 15, 2008 Author Share Posted July 15, 2008 hmmm ill look into it but it happens on all computers on our network Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590321 Share on other sites More sharing options...
DeanWhitehouse Posted July 15, 2008 Share Posted July 15, 2008 send one to me deanwhitehouse6@hotmail.com Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590322 Share on other sites More sharing options...
jesushax Posted July 15, 2008 Author Share Posted July 15, 2008 one should be on the way now, it goes fine to hotmail though you should receive it correctly Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590330 Share on other sites More sharing options...
DeanWhitehouse Posted July 15, 2008 Share Posted July 15, 2008 works fine in windows live mail, i think it is ure server config for outlook, Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590331 Share on other sites More sharing options...
jesushax Posted July 15, 2008 Author Share Posted July 15, 2008 how would i look into this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590332 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 I think you should consult your systems administrator. As this problem is not PHP related anymore, could you please mark the topic as solved Quote Link to comment https://forums.phpfreaks.com/topic/114635-solved-php-mail-goes-to-inbox-as-a-dat-file/#findComment-590335 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.