2014-07-27 74 views
-1

我創建了一個PHP電子郵件flooder,它工作正常。但是,在測試它時,我只能以發件人的電子郵件地址作爲名稱。我想要的是發件人的名字。電子郵件表單發件人名稱而不是電子郵件? (PHP)

下面是代碼。

有人可以幫我嗎?謝謝...

<?php  
$to = $_POST['to'];  
$from = $_POST['ot'];  
$subject = $_POST['tema'];  
$message = $_POST['message'];  

$headers .= "From: ".$from;  

if ($_POST['radio']==="plain")  
{  
$headers = "Content-type: text/plain; charset=UTF-8 \r\n"; 
$headers .= "From: ".$from;  
}  
elseif ($_POST['radio']==="html") 
{  
$headers = "Content-type: text/html; charset=UTF-8 \r\n"; 
$headers .= "From: ".$from;  
}  
mail($to, $subject, $message, $headers);  

?> 
+0

你能發佈html表單呢? – thepratt

回答

1

嘗試這樣:

$headers .= "From: Name of the sender <".$from.">"; 
0

假設形式有一個名爲輸入字段 「真實姓名」 Y會寫下面的代碼:

<?php 
$to = $_POST['to'];  
$from = $_POST['ot']; 
$name = $_POST['realname']; 
$subject = $_POST['tema'];  
$message = $_POST['message'];  

if ($_POST['radio']==="plain")  
{  
    $headers .= "Content-type: text/plain; charset=UTF-8 \r\n"; 
} 
elseif ($_POST['radio']==="html") 
{  
    $headers .= "Content-type: text/html; charset=UTF-8 \r\n"; 
} 
$headers .= "From: $name <$from>";  

mail($to, $subject, $message, $headers); 
?> 
相關問題