简体   繁体   中英

PHP contact form not sending email even after saying email sent

I've put together a simple PHP contact form on my website. When I submit the message its says message sent. But I don't receive the email.

The code I'm using is below

<?php
    $action=$_REQUEST['action'];

    if ($action=="") /* display the contact form */
    {
?>

<form action="" method="post" enctype="multipart/form-data">
    <input type="hidden" name="action" value="submit">
    <div class="field half first">
        <label for="name">Name</label>
        <input name="name" id="name" type="text" placeholder="Name">
    </div>
    <div class="field half">
        <label for="email">Email</label>
        <input name="email" id="email" type="email" placeholder="Email">
    </div>
    <div class="field">
        <label for="message">Message</label>
        <textarea name="message" id="message" rows="6" placeholder="Message"></textarea>
    </div>
    <ul class="actions">
        <li><input value="Send email" class="button alt" type="submit"></li>
    </ul>
</form>

<?php
    } 
    else /* send the submitted data */
    {
        $name=$_REQUEST['name'];
        $email=$_REQUEST['email'];
        $message=$_REQUEST['message'];

        if (($name=="")||($email=="")||($message==""))
        {
            echo "All fields are required, please fill <a href=\"\">the form</a> again.";
        }
        else{       
            $from="From: $name<$email>\r\nReturn-path: $email";
            $subject="Message sent using your contact form";
            mail("xyz@website.com", $subject, $message, $from);
            echo "Email sent!";
        }
    }  
?>

The MX records are set for google apps, would that have anything to do with why the email is not being sent?

Your code seems fine to me.

If you are doing this on localhost, it may be that the address you send your mail to rejects it because SMTP is not properly configured.

Try uploading this to a remote server if that is the case. Or configure SMTP on your computer.

I fixed it, it is a godaddy issue, the MX Entry >> Mail routing needs to be set to

Remote.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM