<?php
if (isset($_POST["sendMessage"])) {
$firstName = trim($_POST['firstName']);
$lastName = trim($_POST['lastName']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$message = trim($_POST['message']);
$from = 'somebody@gmail.com';
$to = 'someone@gmail.com';
$subject = 'webmaster@example.com';
$txt = 'Prottyasha School';
$headers = "From: somebody@gmail.com" . "\r\n" .
"CC: somebody@gmail.com";
$body = "From: First-Name: $firstName\n Last-Name: $lastName\n
E-Mail: $email\n Phone: $phone\n Message: $message";
//echo "success?";
if (mail($to, $subject, $body, $headers)) {
$result = '<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result = '<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
echo $result;
}
?>
它工作正常,但我想让它验证。假设某人提供了无效的电话号码或电子邮件,那么它将通过无效的邮件或电话号码发送消息。我想让它完全验证。有人请帮帮我。
答案 0 :(得分:0)
我认为无法检查邮件是否已成功发送。当邮件被接受传递或发送到本地电子邮件服务时,mail()
返回布尔值true。无法知道该电子邮件是否已发送给收件人。