0
나는 이것을 시도하기 위해 처음입니다, 나는 $to:my gmail
을 제출했습니다. 제출을 클릭하면 어떤 오류도 보이지 않지만 내 Gmail에는 어떤 메일도받지 못했습니다. 뭐가 문제 야? 내가 그랬어 :이메일로 양식 세부 사항을 보내십시오.
<html>
<body>
<form method="post" name="myemailform" action="form-to-email.php">
<p>
<label for='name'>Enter Name: </label><br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Enter Email Address:</label><br>
<input type="text" name="email">
</p>
<p>
<label for='message'>Enter Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" name='submit' value="submit">
</form>
</body>
</html>
PHP를 -
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = '[email protected]';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "[email protected]";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
폼 email.php로-에 어떤 $email_from
에 대해? 유효한 이메일이어야합니다. 나는 제출하는 동안 [email protected]
몇 가지 잘못된 이메일을 입력하면 메일을받지 못하겠습니까?
그러나 iam은 어떤 메일도받지 않습니다. IU에서 $ g에 대한 Gmail 아이디를 –
으로 지정했습니다. 스팸 폴더를 확인 했습니까? 스팸 메일은 알려진 출처의 이메일이 아닌 경우 스팸으로 갈 수 있습니다. – Devesh