简体   繁体   中英

Simple php contact form issue, not sending

Building a website for a client but the contact form is refusing to work, I set the client up with an email account 'contact@eunicedcolvin.co.uk' but it doesn't appear to finish sending it off to load the success message, here is the code below. Im fairly new to PHP but can't figure out what the issue is.

<div id="contact-form" style="background: none;">

            <div id="contact-header"></div>

                <div id="contact-middle">

            <?php 
            if ($_POST["email"]<>'') {  
                $ToEmail = 'contact@eunicedcolvin.co.uk'; 
                $EmailSubject = 'Website Contact'; 
                $mailheader = "From: ".$_POST["email"]."\r\n"; 
                $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
                $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
                $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
                $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
                $MESSAGE_BODY .= "Comment: ".n12br($_POST["comment"])."<br>"; 
                mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
                ?> 
                <div id="contact-success">
                <span style="font-size:16px; font-weight:bold; ">Thanks! Your message was sent</span><br>
                I will get back to you as soon as I can
                </div>
                </div>
        <?php 
        } else { 
        ?>       
      <form method="POST">
        <table width="360" border="0" cellspacing="8" cellpadding="0" style="margin-left: 11px;">
          <tbody><tr>
            <td class="contact-label">Your name:<br></td>
            <td class="contact-text-border"><input name="name" type="text" id="name" size="32" class="contact-name"></td>
            </tr>
          <tr>
            <td class="contact-label">Your Email address:</td>
            <td class="contact-text-border"><input name="email" type="text" id="email" size="32" class="contact-name"></td>
            </tr>
          <tr>
            <td class="contact-label">Comment:</td>
            <td class="contact-text-border" style="padding: 2px 2px;"><textarea name="comment" cols="45" rows="6" id="comment" class="contact-comment"></textarea></td>
            </tr>
          <tr>
            <td height="33" class="contact-label">&nbsp;</td>
            <td align="left" valign="top">
            <input type="submit" name="Submit" class="submit" value="."></td>
            </tr>
          </tbody></table>
        </form> 
        <?php 
        };      
        ?>

        </div>
        <div id="contact-bottom"></div>
            </div>

        </div>

if you'd like to see a sample of it live, its here: http://www.eunicedcolvin.co.uk/contact.html

link to website

The thing is, originally it was set up to post to my personal email to test, then when i swapped it over it refused to work! been racking my brains over this for a while now :S

Your email sending server is most likely not setup correctly.

If it is in fact sending, then its probably get spam filtered.

Also you should not set the from address to the submitted address in the form, as your server will not be authorized to send from that domain.

To try your server is configured mail or not :

if(@mail($emailRecipient, $subject, $message, $headers))
{
  echo "Mail Sent Successfully";
}else{
  echo "Mail Not Sent";
}

use this code, upload it to simple x.php file with just this code (mail etc is inserted), you know that your server is just ok or not :)...

or might be it's put to spam folder of the receiver

Use SMTP.

Don't spend time trying to make mail work.... In my opinion it's just a waste of time, and most emails sent with it, end up in SPAM folder.

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