2016-04-24 160 views
1

我想發送到用戶歡迎消息註冊後,但它沒有發送任何東西到電子郵件,但數據插入數據庫 你能請幫助我弄清楚什麼是錯我的代碼發送給用戶歡迎電子郵件註冊後在php

$email = $_POST['email'];  
$query2 = mysql_query("INSERT INTO facultymember (pin,ID,firstname,midname,lastname,phone,email,password,Door_Num) Values('".$_POST["type"]."','".$_POST["FMID"]."','".$_POST["firstname"]."','".$_POST["middlename"]."','".$_POST["lastname"]."','".$_POST["phone"]."','".$_POST["email"]."','".$_POST["password"]."','".$_POST["Door_NUM"]."')", $connection); 
    $message = "Add Successfully"; 

if($query2) 
{ 

$subject = "Email Verification mail"; 
$headers = "From: [email protected] \r\n"; 
$emessage = "welcome"; 
mail($email,$subject,$emessage,$headers); 
} 
+0

你有沒有配置郵件服務器使用等?你是否自己或其他地方託管它? –

+0

不,我沒有這樣做 –

+0

然後就是這個問題。您需要在php.ini中配置郵件功能。 –

回答

0

試試下面這段代碼:

$to  = $email; // Send email to our user 
$subject = "Email Verification mail"; // Give the email a subject 
$emessage = "welcome"; 

// if emessage is more than 70 chars 
$emessage = wordwrap($emessage, 70, "\r\n"); 

// Our emessage above including the link 
$headers = array(); 
$headers[] = "MIME-Version: 1.0"; 
$headers[] = "Content-type: text/plain; charset=iso-8859-1"; 
$headers[] = "From: no-reply <[email protected]>"; 
$headers[] = "Subject: {$subject}"; 
$headers[] = "X-Mailer: PHP/".phpversion(); // Set from headers 

mail($to, $subject, $emessage, implode("\r\n", $headers)); 
+0

Walaikumalsalam,謝謝你的幫助,但它沒有工作 –

+0

,但它對我工作很好。它可能是服務器錯誤。聯繫你的服務器管理員或者您自己託管您的網站,請嘗試正確配置電子郵件系統。 – shafiul

+0

bro請嘗試編輯的代碼,然後看看結果。請提供反饋 – shafiul

相關問題