Jump to content

mail function


gigas10

Recommended Posts

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;
}

?>

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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 8)

Link to comment
Share on other sites

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..

 

 

Link to comment
Share on other sites

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."'");

?>

Link to comment
Share on other sites

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]

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.