簡體   English   中英

PHP頁面未發送電子郵件

[英]PHP Page is not Sending 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郵件功能有些mixed幸。 您可以在PHP郵件功能頁面http://www.php.net/manual/zh-CN/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
        );
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM