我有一段代碼,經批准發送郵件到電子郵件地址的郵件。電子郵件未被髮送。我需要在我的Web服務器上配置什麼?發送使用PHP
function mailpassword($email, $password){
//notify that the password has been changed
mysqli_select_db($connect,"members");
$query = "select email from users where email = '".$email."'";
$mailquery = mysqli_query($connect,$query);
if(!$mailquery)
{
throw new Exception ('The entered email address could not be found');
}
else if($mailquery->num_rows==0)
{
throw new Exception ('The entered email address could not be found');
//username not in database
}
//if no errors, send mail
else
{
$row = $mailquery->fetch_object();
$email = $row->email;
$from = "From : [email protected] \r\n";
$mesg = "Hey,\n\n You requested for a new password. We have generated a completely random password for you, use it to login.\n\n
New Password - ".$password."\r\n
Please change this random password to a password of your choice once you log in. To change your password, click on the Accounts tab present in your dashboard.\r\n
Cheers\r\n
Hap";
if(mail($email, 'Password Change Account Details', $mesg, $from))
{
return true;
echo "great";
}
else
{
echo "Something went wrong";
}
}
$mails = mailpassword();
}
你可以測試但不帶'$ from'場。它在':'和'\ r \ n'之前包含無關的空格(如果它是最後一個/唯一的標題,它也應該省略)。 – mario 2011-03-12 14:56:03
@mario - 好點,注意。我將來會這樣做 – 2011-03-12 15:08:02