PHP 页面不发送电子邮件

标签 php html sql forms email

我有一个页面,其中有一个表单供用户输入他们的电子邮件。提交表单后,电子邮件将在我的 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

非常感谢所有帮助。感谢您的帮助。

最佳答案

我在使用 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
        );
}

关于PHP 页面不发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22565467/

相关文章:

php - 在 PHP 中循环处理单选按钮

php - 通过 Javascript 访问 HTTP GET 请求

php - 无法计数 : of NULL cells in a column of a table

sql - 是否可以从 SQL 查询执行文本文件?

html - 为什么我的网站链接不显示预览?

mysql - 使用 SQL 数据库中另一个表中的数据从两个表中获取数据

javascript - 将 php key 转换为 javascript 以进行日志记录

php - Mysql INSERT INTO 无法正常工作

javascript - 创建部分 View 以在索引页面中创建新内容

html - 为什么我带圆圈的 div 与 li 的其余部分不一致?