2017-03-06 26 views
0

我似乎無法找到一個解決方案,在網站上。我想要做的是讓用戶點擊一個按鈕。然後,這將發送一封郵件給我或辦公室的某個人,然後郵件將包含登錄的用戶詳細信息。我正在發送郵件,但我不確定如何讓代碼向我發送用戶信息。這裏是我的代碼:發送登錄用戶的詳細信息到管理員按鈕單擊使用phpmailer

include 'contact/config.php'; 

require_once 'class.user.php'; 
$user_home = new USER(); 

if(!$user_home->is_logged_in()) 
{ 
    $user_home->redirect('index.php'); 
} 

$stmt = $user_home->runQuery("SELECT * FROM tbl_client_info WHERE UCODE=:uid"); 
$stmt->execute(array(":uid"=>$_SESSION['userSession'])); 
$row = $stmt->fetch(PDO::FETCH_ASSOC); 

error_reporting (E_ALL^E_NOTICE); 

$post = (!empty($_POST)) ? true : false; 

if($post) 
{ 

$name = $row['firstname']; 
$email = $row['billingemail']; 
$subject = "myDraadloze Package Contact Card"; 
$message = stripslashes($_POST['Please contact user regarding example']); 


$error = ''; 



if(!$error) 
{ 
$mail = mail(WEBMASTER_EMAIL, $subject, $message, 
    "From: ".$name." <".$email.">\r\n" 
    ."Reply-To: ".$email."\r\n" 
    ."X-Mailer: PHP/" . phpversion()); 


if($mail) 
{ 
echo 'OK'; 
} 

} 


} 
?> 

任何幫助,將不勝感激。

謝謝

+0

我建議閱讀PHP文檔,並使用PHPMailer標記此問題。 – Synchro

回答

1
include 'contact/config.php'; 

    require_once 'class.user.php'; 
    $user_home = new USER(); 

if(!$user_home->is_logged_in()) 
{ 
$user_home->redirect('index.php'); 
    } 
else 
{ 
$stmt = $user_home->runQuery("SELECT * FROM tbl_client_info WHERE UCODE=:uid"); 
$stmt->execute(array(":uid"=>$_SESSION['userSession'])); 
    $row = $stmt->fetch(PDO::FETCH_ASSOC); 

    error_reporting (E_ALL^E_NOTICE); 

    $post = (!empty($_POST)) ? true : false; 

if($post) 
    { 

$name = $row['firstname']; 
    $email = $row['billingemail']; 
    $subject = "myDraadloze Package Contact Card"; 
$email_to = " [email protected]"; 


$message = .= "Firstname: ".($name)."\n\n"; 
    $message = .= "Email: ".($email)."\n\n"; 
    $message = .= "Firstname: ".($name)."\n\n"; 


    $error = ''; 


    if(!$error) 
    { 
    $headers = 'From: your Website/email'."\r\n". 
    'Reply-To: [email protected]'."\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 
     if(@mail($email_to, $subject, $message, $headers)) 

    { 

    echo 'OK'; 

    } 



    }} 
    ?> 

希望這有助於!

+0

謝謝。我可以看到你要去哪裏,但是$ name = $ row ['firstname'];實際上並沒有返回一個值。 –

+1

你在db中有這樣的列(名字)嗎?任何錯誤? – Raman

+0

WHERE UCODE =:uid .....我們在哪裏可以找到:uid – Raman

0

答覆和從格式看起來不正確。我只需爲它們創建一個變量,然後將其粘貼在代碼中。

$name = $row['firstname']; 
$email = $row['billingemail']; 
$subject = "myDraadloze Package Contact Card"; 
$message = stripslashes($_POST['Please contact user regarding example']); 


$error = ''; 
$replyemail="'Reply-To: ".$name."<".$email.">'"."\r\n"; //looks likes this 'Reply-to: customer name <[email protected]'\r\n 
$fromemail="'from: ".$name."<".$email.">'"."\r\n"; //looks likes this 'from: customer name <[email protected]'\r\n 

//yours looked like this 
//from:customername <[email protected]\r\n 
//these are headers and need to be seperated with ' 
//the ' should be at start and before \r\n 

if(!$error) 
{ 
$mail = mail(WEBMASTER_EMAIL, $subject, $message,$fromemail.$replyemail 

    ."X-Mailer: PHP/" . phpversion()); 
相關問題