2013-01-23 103 views
0

我試圖編寫腳本,以便在用戶使用PHP成功註冊時向用戶發送郵件。 用戶在數據庫中註冊成功,但未發送電子郵件。 這裏是我的代碼:成功註冊時發送郵件

<?php 
function send_mail($id,$name,$email,$password) 
{ 
    $from='Admin <[email protected]>'; 
    $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)

回答

1

我想你的mail()函數在send_mail()函數之外。

更改成,

function send_mail($id,$name,$email,$password) 
{ 
    $from='Admin <[email protected]>'; 
    $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); 

} 
0

之前,關閉郵件功能後的功能,而不是循環關閉
相關問題