if (mysqli_num_rows($result_verify_email) == 0) { // IF no previous user is using this email .
// Create a unique activation code:
$activation = md5(uniqid(rand(), true));
$query_insert_user = "INSERT INTO `members` ( `Username`, `Email`, `Password`, `Activation`) VALUES ( '$name', '$Email', '$Password', '$activation')";
$result_insert_user = mysqli_query($dbc, $query_insert_user);
if (!$result_insert_user) {
echo 'Query Failed ';
}
if (mysqli_affected_rows($dbc) == 1) { //If the Insert Query was successfull.
// 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: ismaakeel@gmail.com');
// Flush the buffered output.
// Finish the page:
echo '<div class="success">Thank you for
registering! A confirmation email
has been sent to '.$Email.' Please click on the Activation Link to Activate your account </div>';
} else { // If it did not run OK.
echo '<div class="errormsgbox">You could not be registered due to a system
error. We apologize for any
inconvenience.</div>';
}
} else { // The email address is not available.
echo '<div class="errormsgbox" >That email
address has already been registered.
</div>';
}
这是我的代码示例。我使用简单的mail()发送电子邮件,但它不起作用。任何人都可以指出任何错误吗?我没有收到错误消息,但是当我发送电子邮件时,它无法正常工作。我没有收到电子邮件!请帮忙!
答案 0 :(得分:0)
首先,检查您托管脚本的位置。 PC上的Web服务器通常未配置邮件服务器。如果您在共享主机服务上运行脚本,请确保该服务提供对mail()
功能的访问权限,然后联系您的托管服务支持。
如果您在本地服务器上运行脚本,则需要更改php.ini
中的设置以设置邮件功能以使用SMTP;否则,您需要在PC上配置邮件服务器。
此外,如果您在PHP中使用ini_set()
函数,请确保将这些函数包含在与调用mail
函数相同的脚本中,因为this value is only set for the duration of the current scripts execution.