我有一个页面,其中包含供用户输入电子邮件的表单。提交表单后,将在我的MSSQL表中检查电子邮件,如果它存在于表的一行中,它将向用户的电子邮件发送一封电子邮件。现在,我正确地输入了现有的电子邮件,但从未收到过电子邮件。我试图这样做,以便如果用户忘记密码,它将从正确的行检索密码并将该密码发送到用户的电子邮件。
这是我的PHP页面代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
$conn=mssql_connect('gdm','dr','Rd1!');
mssql_select_db('Gdr',$conn);
if (isset($_POST['forgotpass'])) {
$conn=mssql_connect('gdom','GBdr','d1!');
mssql_select_db('Gdr',$conn);
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$email = $_POST['email'];
$querye = "SELECT password FROM staffportal WHERE email = '".$_POST['email']."'";
$check = mssql_query($querye, $conn);
$check2 = mssql_num_rows($check);
echo "".$check2."";
//if the email doesn't exist it gives an error
if ($check2 != 0) {
print"<p>Thank you, dsa we will get back to you.</p>";
print"<p>Today's date isdsa.</p>";
ob_start();
$tae = "".$_POST['email']."";
echo "".$tae."";
$out2 = ob_get_contents();
ob_end_clean();
var_dump($out2);
var_dump($out2);
$to = "".$out2."";
echo "Emailing to: ".$to."";
$subject = "Financing fordsac ";
$body = "dsdasd \n\n";
$headers = "From: info@gbmtd.ca";
mail($to, $subject, $body, $headers);
} else {
echo "Sorry, the email ".$email." is incorrect.";
} } else {
?>
<form method="POST" action="<?php $_PHP_SELF ?>">
Email:<br />
<input type="text" name="email" id="email"/>
<br /><br />
<input type="submit" id="forgotpass" value="Change Password" name="forgotpass"/>
</form>
<?php } ?>
</body>
</html>
点击提交后,我的页面会显示:
1
Thank you, dsa we will get back to you.
Today's date isdsa.
string(22) "kelseynealon@gmail.com" string(22) "kelseynealon@gmail.com" Emailing to: kelseynealon@gmail.com
非常感谢所有帮助。谢谢你的帮助。
答案 0 :(得分:1)
我和PHP邮件功能运气不错。您可以在PHP邮件功能页面http://www.php.net/manual/en/function.mail.php上查找线索。我个人使用PHP SwiftMailer(http://swiftmailer.org/)来发送从PHP应用程序发送的任何电子邮件,它的效果非常好。
这是我使用它的通用函数:
/*
Starting code for sending email via this function:
list($email_logger, $email_mailer) = email_interface();
$message = Swift_Message::newInstance()
->setFrom(array('from@domain.ext' => 'John Doe'))
->setTo(array('to@domain.ext' => 'Jane Doe'))
->setSubject('<SUBJECT>')
->setBody('<BODY>');
$email_mailer->send($message);
*/
// Returns PHP SwiftMailer mailer and logger email interfaces
function email_interface()
{
// Mail configuration
$global_email_config = array(
//'relay_encryption' => 'ssl',
//'relay_host' => 'relayhost.domain.ext',
//'relay_port' => '465',
// 'relay_user' => '<ADDR>',
// 'relay_pass' => '<PASS>',
'smtp_sender' => array(
'sender@domain.ext' => 'Sender Name'
)
);
if (isset($global_email_config['relay_host'])) {
$transport = Swift_SmtpTransport::newInstance();
$transport->setHost($global_email_config['relay_host']);
if (isset($global_email_config['relay_port'])) {
$transport->setPort($global_email_config['relay_port']);
}
if (isset($global_email_config['relay_encryption'])) {
$transport->setEncryption($global_email_config['relay_encryption']);
}
if (isset($global_email_config['relay_user'])) {
$transport->setUsername($global_email_config['relay_user']);
$transport->setPassword($global_email_config['relay_pass']);
}
} else {
$transport = Swift_SendmailTransport::newInstance();
}
$mailer = Swift_Mailer::newInstance($transport);
$logger = new Swift_Plugins_Loggers_ArrayLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
return array(
$logger,
$mailer
);
}