gigas10 Posted July 16, 2008 Share Posted July 16, 2008 Hey everyone, i've got a little problem with the mail() function. So to clarify i'm unluckily running php with IIS and mssql. I'm trying to do send mail to someone if they forgot their password, however when I send mail it always fails. Here is the part of my phpinfo() page, the smtp server is set up correctly because it mails in asp just fine. sendmail_from no value no value sendmail_path no value no value also my code <?php require_once('connectdb.php'); $tnum = $_POST['tnum']; $qry = mssql_query("SELECT passwd, email FROM members WHERE TNumber='$tnum'"); $result = mssql_num_rows($qry); if($result == 1) { $rows=mssql_fetch_array($qry); // keep password in $your_password $your_password=$rows['passwd']; // ---------------- SEND MAIL FORM ---------------- // send e-mail to ... $to=$rows['email']; // Your subject $subject="Forgotten Password"; // From $header="From: $to"; // Your message $messages= "Your password for login to our website \r\n"; $messages.="Your password is $your_password \r\n"; $messages.="more message... \r\n"; // send email $sentmail = mail($to,$subject,$messages,$header); } // else if $count not equal 1 else { echo "Could not find your email in our database<Br> "; } // if your email succesfully sent if($sentmail){ echo "Your Password Has Been Sent To Your Email Address."; echo "<a href=login-form.php>Login Page</a>"; } else { echo "Cannot send password to your e-mail address<br>"; echo $to; } ?> Quote Link to comment Share on other sites More sharing options...
Xurion Posted July 16, 2008 Share Posted July 16, 2008 If the function fails it will be something to do with the configuration. ASP and PHP have different configuration files. Check the PHP config. Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted July 16, 2008 Share Posted July 16, 2008 I too run under IIS with mssql... I have the ip of my exchange server as the sendmail path and just use a generic email as the sendmail from and all seems to work okay. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 16, 2008 Share Posted July 16, 2008 i also am running IIS with PHP and mssql and I have a few mail functions that are working beautifully. here's a snippet of code that I use for mail. <?php $message=" You have been contacted by ".$urname.".\n From ".$organization.". \n Reason for contacting: ".$category." \n ".$urname." is ".$title." @ ".$organization." \n \n\n To contact this person:\n Address: ".$addy." \n City: ".$city." \n State: ".$state." \n E-Mail: ".$email."\n Phone #: ".$phone."\n Comments:\n ".$comments."\n Thank you, Someones Contact Page "; //WHO GETS IT? $to="someone@somewhere.com"; $mail= mail($to,$organization,$message); ?> PS (You have to setup your send FROM email in your php.INI) i'm guessing this is your problem /\ (I also setup my php.ini file to use SMTP for mail) Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 16, 2008 Share Posted July 16, 2008 do a search in your PHP.INI file for this EXACT phrase: [mail function] fill this in i'm betting this is your problem Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 16, 2008 Author Share Posted July 16, 2008 nope like i stated i already filled that stuff in, the sendmail path is only for unix? so that doesnt make sense that its the solution. And sendmail_from just gets over ridden by my headers Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 16, 2008 Share Posted July 16, 2008 well sendmail is not only for unix the exact phrase from the php INI: [mail function] ; For Win32 only. SMTP = YOU SMTP INFO smtp_port = 25 ; For Win32 only. sendmail_from = youremail@yourdomain.com ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ;sendmail_path = and if your headers ARE infact over writing the from then your trying to send email FROM the same person your sending it TO..? hows that work? // send e-mail to ... $to=$rows['email']; // Your subject $subject="Forgotten Password"; // From $header="From: $to"; // SO $header = $rows['email']?? and as for emailing 'Just fine' in 'ASP'... asp is controlled by your windows system.. therefore the setup of the smtp in your php.ini has absolutley NOTHING to do with it. I mean I have pretty much the same setup you do.. and my works just dandy Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 16, 2008 Author Share Posted July 16, 2008 so your telling me you cant email yourself? i do it all the time Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 16, 2008 Share Posted July 16, 2008 sure if your smtp is for the email being sent from Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 16, 2008 Share Posted July 16, 2008 how is my email@yahoo.com email address going to work for my smtp.comcast.net? I mean comcast is pretty good but they are not magicians.. your FROM email has to be registered with your smtp to send emails from it. Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 16, 2008 Author Share Posted July 16, 2008 They all are, this is run on intranet, a huge company. Everyone that will be requesting a password sent to their email will be registered to the system used here and have an account set up already. Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 16, 2008 Author Share Posted July 16, 2008 so what do i do? just use the smtp server for the sentfrom ? Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 16, 2008 Share Posted July 16, 2008 the send from ideally should be your admin email for the network domainName@domain.com other than what has already been said in this topic.. I don't know anything else you could do in order to get this thing to work.. all you should have to have is have the setting in the php.ini set correctly and the php code setup correctly.. I didn't have to install anything extra in php or windows or anything.. I did wonder about login issues with the smtp but I never needed to setup anything for login.. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 16, 2008 Share Posted July 16, 2008 try changing this: <?php $header="From: $to"; ?> to this <?php $header="From: ".$to; ?> and then change this <?php $qry = mssql_query("SELECT passwd, email FROM members WHERE TNumber='$tnum'"); ?> to this: <?php $qry = mssql_query("SELECT passwd, email FROM members WHERE TNumber=' ".$tnum."'"); ?> Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 16, 2008 Author Share Posted July 16, 2008 nope no luck, there must be something configured incorrectly with the server or mail server. Although i cant do anything about it Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 16, 2008 Share Posted July 16, 2008 what errors are you getting.. can you post them plz? Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 16, 2008 Share Posted July 16, 2008 even if there was something wrong with your mail server.. php would not be able to recognize it.. so the script would still finish successfully Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 16, 2008 Author Share Posted July 16, 2008 im getting the built in error in the code, which says Could not send to your email. So its failing on if($sentmail) Quote Link to comment Share on other sites More sharing options...
rad131304 Posted July 16, 2008 Share Posted July 16, 2008 do you get anything if you just echo $sendmail;? Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 17, 2008 Share Posted July 17, 2008 change this line to this so we can see some error codes <?php echo "Cannot send password to your e-mail address<br>"; ?> to this: <?php echo("Cannot send password to your e-mail address<br>" . mssql_get_last_message ()); ?> [code] [/code] Quote Link to comment 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.