为什么联系表格不向客户发送电子邮件?

时间:2013-05-10 12:11:05

标签: php html forms contact spam

当我将电子邮件更改为我的个人Hotmail地址时,该邮件会显示 - 尽管它位于我的垃圾邮件文件夹中。但是当我将其更改为客户端的电子邮件时,该消息根本没有显示。有谁知道如何解决这个问题?

这是表单的PHP:

<?php 
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$address = $_POST['address'];
$number = $_POST['number'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = 'Message from Reef Cleaning solutions website';
$to = 'info@address.co.uk';

if (empty($name) || empty($address) || empty($number) || empty($email) || empty($subject) || empty($message)) {
    if (empty($name))
        $error['name'] = "Please enter your Full Name";
    if (empty($address))
        $error['address'] = "Please enter your address";
    if (empty($number))
        $error['number'] = "Please enter a contact number";
    if (empty($email))
        $error['email'] = "Please enter a valid Email Address";
    if (empty($message))
        $error['message'] = "Please write a message, enquiries or other concerns above";
}
else { //if not empty
    $body = "
    Name: $name\r\n
    Address: $address\r\n
    Number: $number\r\n
    Email: $email\r\n
    Message: $message
    ";

    $headers="From: {$email}\r\nReply-To: {$email}"; //create headers for email

    if(mail($to,$subject,$body,$headers))
    {
      $success = "mail has been sent";
    }
    else
    {
     echo "error during sending mail";
    }
}
}
?>

这是HTML

 <form method="POST">
       <table border="1">
            <tr>
            <td><label for="name" class="g">Name</label></td>
            <td><input id="name" name="name" type="text" autofocus required /></td>
            </tr>

            <tr>
            <td><label for="address" class="g">Address</label></td>
            <td><textarea rows="3" id="address" name="address" cols="50"></textarea></td>
            </tr>

            <tr>
            <td><label for="number" class="g">Contact number</label></td>
            <td><input id="number" name="number" type="text" autofocus required /></td>
            </tr>

            <tr>
            <td><label for="email" class="g">Email</label></td>
            <td><input id="email" name="email" type="text" placeholder="example@domain.com" autofocus required /></td>
            </tr>

            <tr>
            <td><label for="message" class="g">Enquiry</label></td>
            <td><textarea rows="3" id="message" name="message" required cols="50"></textarea></td>
            </tr>
            </table>
            <input type="submit" value="Submit" name="submit" />

            <div id="message-sent"> 
            <?php
            if ($success) {
                echo $success;
            }
            ?>
            </div>

            </form>

1 个答案:

答案 0 :(得分:0)

如果您收到电子邮件中的消息,则PHP代码不会出现问题,因为它已成功发送邮件。

那么,配置的电子邮件是否正确?你能用你的个人地址发送电子邮件到这个地址吗?

您告诉该电子邮件被认为是您个人地址上的垃圾邮件,可能与其他地址相同,但该邮件不属于“垃圾邮件”文件夹,但不允许进入邮箱。