联系表格不发送电子邮件到我的具体地址
我在我的网站上有一个php联系表格。它发送我的电子邮件在我的正常地址。但是当我在'to'部分输入所需的邮件收件人地址时。我没有收到任何电子邮件。可能是什么问题??联系表格不发送电子邮件到我的具体地址
<?php
\t if (isset($_POST["submit"])) {
\t \t $name = $_POST['name'];
\t \t $number = $_POST['number'];
\t \t $email = $_POST['email'];
\t \t $message = $_POST['message'];
\t \t $from = ' Contact Form';
\t \t $to = '';
\t \t $subject = 'Message from Website contact page ';
\t \t
\t \t $body ="From: $name\n Number: $number\n E-Mail: $email\n Message:\n $message";
\t \t // Check if name has been entered
\t \t if (!$_POST['name']) {
\t \t \t $errName = 'Please enter your name';
\t \t }
\t \t
\t \t if (!$_POST['number']) {
\t \t \t $errNumber = 'Please enter your mobile number';
\t \t }
\t \t
\t \t // Check if email has been entered and is valid
\t \t if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
\t \t \t $errEmail = 'Please enter a valid email address';
\t \t }
\t \t
\t \t //Check if message has been entered
\t \t if (!$_POST['message']) {
\t \t \t $errMessage = 'Please enter your message';
\t \t }
\t \t
// If there are no errors, send the email
if (!$errName && !$errNumber && !$errEmail && !$errMessage) {
\t if (mail ($to, $subject, $body, $from)) {
\t \t $result='<div class="alert alert-success">Thank You! We will get in touch with you soon.</div>';
\t } else {
\t \t $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
\t }
}
\t }
?>
你可以检查此:
$to = "[email protected], [email protected]";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: [email protected]" . "\r\n";
// Check if name has been entered
$errName = '';
if ($_POST['name'] == '') {
$errName = 'Please enter your name';
}
//Other validation messages here...
// If there are no errors, send the email
if ($errName == '' && $errNumber == '' && $errEmail == '' && $errMessage == '') {
if (mail ($to, $subject, $body, $headers)) {
$result='<div class="alert alert-success">Thank You! We will get in touch with you soon.</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
}
试过。仍然不起作用。它可能是我的企业电子邮件主机提供商的一些问题? –
对不起,我不太确定。对于其他邮件ID,它工作正常吗? – Sinto
是的。它为所有其他人工作。我的网站托管在一台服务器上,电子邮件托管在另一台服务器上。这可能是麻烦的原因吗?我的网站是否无法与电子邮件主机通信? –
所以你没有得到邮件所需的邮件收件箱?您是否在新邮件帐户的收件箱/垃圾邮件中检查过它 – Sinto
是的,我检查过。一无所获。 –