cancel
Showing results for 
Search instead for 
Did you mean: 

PHP Email Form not working.

Hi. I paid for the coding of my site and don't know much about javascript/php/etc, only some minimal html and css. (enough to make small changes).

 

For whatever reason, the form is not sending to the email hooked up with my domain. I've sent about 20 times to make sure it wasn't going to spam/sending a handful but not sending others. 

 

Here is the code (leaving out the email and putting you@yoursite instead for this question so i don't get spam...) :

<?php
$errors  = '';
$myemail = 'you@yoursite.com';
if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['message'])) {
    $errors .= "\n Error: Required Field";
}

$name    = $_POST['name'];
$email   = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email)) {
    $errors .= "\n Error: Invalid Email Address";
}

if (empty($errors)) {
    $to            = $myemail;
    $email_subject = "$subject";
    $email_body    = "\n Name: $name \n Email: $email \n Subject: $subject \n Message: \n $message";
    $headers       = "From: $email";
    
    mail($to, $email_subject, $email_body, $headers);
}
?>

 

4 REPLIES 4

Re: PHP Email Form not working.

I've discovered that it works from OTHER emails, but not mine. I'm not certain why this is but it's frustrating. 

Community Manager
Community Manager

Re: PHP Email Form not working.

Hi @Nnamier. Thanks for being part of GoDaddy Community! If the form can send to other addresses, then the issue is more likely with your address receiving the message than with the form sending it. If you look on the receiving end, that can be quite a few things. You may want to share your domain so the community can take a look to see if there are any common DNS issues. You may also consider posting more details on the Managing Email board if you're not getting an answer here. 

 

JesseW - GoDaddy | Community Manager | 24/7 support available at x.co/247support | Remember to choose a solution and give kudos.

Re: PHP Email Form not working.

I can't get the thing to work to any email address. Can this be fixed or is there a workaround?

Re: PHP Email Form not working.

check that the phpmail function is enabled on your hostingSmiley Happy, often hosting providers disable it by default


don't worry be happy Smiley Happy