我正在尝试编写脚本,以便在用户使用PHP成功注册后向其发送邮件。用户在数据库中成功注册,但未发送电子邮件。这是我的代码:
<?php
function send_mail($id,$name,$email,$password)
{
$from='Admin <admin@mydomain.com>';
$headers = '';
$headers .= "From: $fromn";
$headers .= "Reply-to: $fromn";
$headers .= "Return-Path: $fromn";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">n";
$headers .= "Date: " . date('r', time()) . "n";
$headers .= "MIME-Version: 1.0" . "rn";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "rn";
}
$subject = "Welcome!";
$message = "
<p></p><br>
Hi ".$name."<br>
Thank you for registering for the event.<br><br>
Your ID is ".$id."<br>
Login using your email id : ".$email." and,<br>
your password : ".$password."<br><br>
";
mail($email,$subject,$message,$headers);
?>
在我的register.php
脚本中,我包括:
send_mail($u_id,$u_name,$_POST['email'],$password)
函数的参数是id
(INT),name
(VARCHAR),email
(VARCHAR)和password
(VARCHAR)。
我认为你的mail()函数在send_mail()函数之外。
把它改成,
function send_mail($id,$name,$email,$password)
{
$from='Admin <admin@mydomain.com>';
$headers = '';
$headers .= "From: $fromn";
$headers .= "Reply-to: $fromn";
$headers .= "Return-Path: $fromn";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">n";
$headers .= "Date: " . date('r', time()) . "n";
$headers = "MIME-Version: 1.0" . "rn";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "rn";
$subject = "Welcome!";
$message = "
<p></p><br>
Hi ".$name."<br>
Thank you for registering for the event.<br><br>
Your ID is ".$id."<br>
Login using your email id : ".$email." and,<br>
your password : ".$password."<br><br>";
mail($email,$subject,$message,$headers);
}
在邮件函数之后关闭函数循环,而不是在 sub 之前关闭