我想知道是否有可能從本地主機發送電子郵件?我試過一些東西,但沒有奏效,我想也許它不會在本地主機上工作。下面的代碼:電子郵件發送本地主機
// Send the email:
$message = " To activate your account, please click on this link:\n\n";
$message .= WEBSITE_URL . '/activate.php?email=' . urlencode($Email) . "&key=$activation";
mail($Email, 'Registration Confirmation', $message, 'From: [email protected]');
// Flush the buffered output.
// Finish the page:
echo '<div class="success">Thank you forregistering! A confirmation email has been sent to '.$Email.' Please click on the Activation Link to Activate your account </div>';
而這裏的連接:
/*Define constant to connect to database */
DEFINE('DATABASE_USER', 'root');
DEFINE('DATABASE_PASSWORD', 'buena');
DEFINE('DATABASE_HOST', 'localhost');
DEFINE('DATABASE_NAME', 'forum');
/*Default time zone ,to be able to send mail */
date_default_timezone_set('UTC');
/*You might not need this */
ini_set('SMTP', "mail.myt.mu"); // Overide The Default Php.ini settings for sending mail
//This is the address that will appear coming from (Sender)
define('EMAIL', '[email protected]');
/*Define the root url where the script will be found such as http://website.com or http://website.com/Folder/ */
DEFINE('WEBSITE_URL', 'http://localhost');
// Make the connection:
$dbc = @mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD,
DATABASE_NAME);
if (!$dbc) {
trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}
這有什麼錯?還是失蹤?
這將在localhost上正常工作,但您需要在其上設置一個smtp服務器。 – andrewsi
哦,就是這樣。我對此並不熟悉。但我會做一些研究。感謝您對我發現一個問題,關於我的答案提示:) –