0

我正在尝试编写一个脚本,以便在他/她使用 PHP 成功注册后向用户发送邮件。尽管没有发送电子邮件,但用户在数据库中注册成功。这是我的代码:

<?php
function send_mail($id,$name,$email,$password)
{   
    $from='Admin <admin@mydomain.com>';
    $headers = '';
    $headers .= "From: $from\n";
    $headers .= "Reply-to: $from\n";
    $headers .= "Return-Path: $from\n";
    $headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
    $headers .= "Date: " . date('r', time()) . "\n";
    $headers .= "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

}
$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)

4

2 回答 2

1

我认为您的 mail() 函数在 send_mail() 函数之外。

改成,

function send_mail($id,$name,$email,$password)
{   
    $from='Admin <admin@mydomain.com>';
    $headers = '';
    $headers .= "From: $from\n";
    $headers .= "Reply-to: $from\n";
    $headers .= "Return-Path: $from\n";
    $headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
    $headers .= "Date: " . date('r', time()) . "\n";
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

    $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);

}
于 2013-01-23T10:49:08.087 回答
0

在 mail 函数之后关闭函数循环而不是在 sub 之前关闭

于 2013-01-23T10:53:32.207 回答