2016-10-04 2 views
1

이 메일 폼에는 보낸 사람이없고 메일이 곧장 쓰레기통으로가는 것을 제외하고는 모든 것이 작동합니다! 이 우편물에 발신자가 없기 때문입니까? 발신자로부터 정보를 얻으 려하므로 보낸 사람의 코드를 어디서 채울 수 있습니까?발신자가있는 PHP 메일

+0

: 메일을 보낼 때 메일 헤더에서을 포함해야합니다. 이는 additional_headers 매개 변수로 설정하거나 php.ini에서 기본값을 설정할 수 있습니다. – Progrock

+0

그런데, 저는 방금 램프 설정을 확인했고, 내 설정에는 'sendmail_from'값이 정의되어 있지 않습니다. 내 메일러 (exim4)는 헤더를 추가하지 않으면 스크립트를 실행하는 사용자의 보낸 사람 필드를 추가합니다. From 헤더가 전혀 없습니까? – Progrock

답변

2
당신은 메일로 "추가 헤더"인수를 사용하여 보낸 사람의 이메일 주소를 추가 할 수 있습니다

<?php 
/* Set e-mail recipient */ 
$myemail = "[email protected]"; 

/* Check all form inputs using check_input function */ 
$name = check_input($_POST['inputName'], "Your Name"); 
$email = check_input($_POST['inputEmail'], "Your E-mail Address"); 
$subject = check_input($_POST['inputSubject'], "Message Subject"); 
$message = check_input($_POST['inputMessage'], "Your Message"); 

/* If e-mail is not valid show error message */ 
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) 
{ 
show_error("Invalid e-mail address"); 
} 
/* Let's prepare the message for the e-mail */ 


$message = " 

Someone has sent you a message from xxxxxxx.com: 

Name: $name 
Email: $email 
Subject: $subject 

Message: 
$message 

"; 

/* Send the message using mail() function */ 
mail($myemail, $subject, $message); 

/* Redirect visitor to the thank you page */ 
header('Location: http://www.xxxxxxx.com/confirmation.html'); 
exit(); 

/* Functions we used */ 
function check_input($data, $problem='') 
{ 
$data = trim($data); 
$data = stripslashes($data); 
$data = htmlspecialchars($data); 
if ($problem && strlen($data) == 0) 
{ 
show_error($problem); 
} 
return $data; 
} 

function show_error($myError) 
{ 
?> 
<html> 

    <body> 

    <p>Please correct the following error:</p> 
    <strong><?php echo $myError; ?></strong> 
    <p>Hit the back button and try again</p> 

    </body> 
</html> 
<?php 
exit(); 
} 
?> 
:

mail($myemail, $subject, $message, "From: [email protected]"); 

편집을 : 귀하의 경우에, 나는 당신이 $ 이메일에 전달할 필요가 있다고 생각 변수에서 앞에서 정의한 변수. 그러면 양식에 입력 된 이메일 주소에서 온 것으로 이메일이 표시됩니다.

mail($myemail, $subject, $message, "From: " . $email); 

참조 : 수동 (메일)에서 http://php.net/manual/en/function.mail.php

+0

시간 내 주셔서 감사합니다! 그러나 내가 메일을 얻었을 때 누가 헤더에서 왔는지보고 싶다. 이 예에서는 [email protected] 또는 내가 작성한 이메일을 말합니다. – Riesbeck

+0

감사합니다. Will! – Riesbeck