Jump to content

How can I fix an email o Godaddy?


Devilowy
Go to solution Solved by fastsol,

Recommended Posts

Hi I've created my website, I'm hosting it on Godaddy but my email doesn't work at all, it shows the errors so it looks like it works and the mail has been sent, but i don't get any emails at all. I used different emails, one from Gmail and one from Godaddy.  I've been loking for the solution for that for last few days... can you help, please?
This is the code:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Contact</title>  
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="index.css"/>  
</head>    


<body>
<?php


function spamcheck($field) {
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);
  if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
    return TRUE;
  } else {
    return FALSE;
  }
}
?>


<?php
if (!isset($_POST["submit"])) {
  ?>


    <div class="mail">
      <p class="text">Fill the form below and send it.</p><br>
      <div id="form">
          <form class="formContact" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">


              <div class="userid">
            <p class="descr">Customer ID:</p><input type="text" name="userid">
              </div>
            <p class="descr">Name:</p><input type="text" name="username">
            <p class="descr">Email:</p><input type="email" name="email">
                <p id="p">or</p>
            <p class="descr">Tel.no:</p><input type="text" name="usertel">
            <p class="descr">Message:</p><textarea rows="7" cols="60" name="inquiry"></textarea>
            <br><br><br><br><br><br>
            <input class="button" name="submit" type="submit" value="Send">


          </form>


  <?php
} else {
  if (isset($_POST["username"])) {
    $mailcheck = spamcheck($_POST["email"]);
    if ($mailcheck==FALSE) {
      echo "<p class='error'>Invalid input</p><br>";
      echo "<p class='error'>Go back to the form and make sure that you:</p><br>";
      echo "<p class='error'>-Enter your name</p>";
      echo "<p class='error'>-Enter a correct email address</p>";
      echo "<p class='error'>-Fill the message box</p>";
    } else {
      $username = $_POST['username'];
      $userid = $_POST['userid'];
      $email = $_POST['email'];
      $usertel = $_POST['usertel'];
      $inquiry = $_POST['inquiry'];


$to = "myemail@domain.com";
$subject = "$username";
$email_message .= 'Content-type: text/html; charset=utf-8' . "\n";           
$email_message = "Name: $username\n";
        function clean_string($string) {
            $bad = array("content-type","bcc:","to:","cc:","href");
            return str_replace($bad,"",$string);
        }
        
$email_message .= "ID: ".clean_string($userid)."\n";
$email_message .= "Tel: ".clean_string($usertel)."\n";
$email_message .= "Email: ".clean_string($email)."\n\n";
$email_message .= "Message: ".clean_string($inquiry)."\n";
        


      mail($to,$subject,$email_message,$headers);
      echo "<p class='success'>Thank you, your message has been sent successfully</p><br>";
      echo "<p class='info'>We will respond to your message within 24 hours.</p>"; 
    }
  }
}
?>
      </div>
  </div>
 </body>
</html>

 

Link to comment
Share on other sites

  • Solution

Like Ginerjm says, you're overwriting the first $email_message because the second one doesn't have a .= but rather a =

But there are a few other things that are wrong also.  Most likely you meant to make the first $email_message be $headers instead.  You're calling $headers in the mail() but you're not defining $headers anywhere.  The line that would be considered a header is the first $email_message line.  But even still you are missing some other crucial email headers like these

$headers = 'MIME-Version: 1.0' . "\r\n"; // This might not be super crucial, but is generally sent.
$headers .= 'Content-Type: text/html; charset=iso-8859-1' . "\r\n"; //This one you already have.
$headers .= 'From: email@yourdomain.com <email@yourdomain.com>' . "\r\n"; // This one is very important. Replace the emails on this line with an actual email address at your domain.

Those are just the minimum required headers.  You honestly should be using a mailing library like PHPMailer, it will send all the required headers automatically and you can do a lot more than that with it.  Sending email effectively is not as simple as the mail(), there is a ton more to it than that.

Edited by fastsol
Link to comment
Share on other sites

Like Ginerjm says, you're overwriting the first $email_message because the second one doesn't have a .= but rather a =

But there are a few other things that are wrong also.  Most likely you meant to make the first $email_message be $headers instead.  You're calling $headers in the mail() but you're not defining $headers anywhere.  The line that would be considered a header is the first $email_message line.  But even still you are missing some other crucial email headers like these

$headers = 'MIME-Version: 1.0' . "\r\n"; // This might not be super crucial, but is generally sent.
$headers .= 'Content-Type: text/html; charset=iso-8859-1' . "\r\n"; //This one you already have.
$headers .= 'From: email@yourdomain.com <email@yourdomain.com>' . "\r\n"; // This one is very important. Replace the emails on this line with an actual email address at your domain.

Those are just the minimum required headers.  You honestly should be using a mailing library like PHPMailer, it will send all the required headers automatically and you can do a lot more than that with it.  Sending email effectively is not as simple as the mail(), there is a ton more to it than that.

Days of searching, I started losing hope that i can finish my website, I was reading through other posts on different forums, pages of reading.... and you just did it in short advice. Thank you, finally someone that knows how to solve the problem within only one post!

Edited by Devilowy
Link to comment
Share on other sites

the key to solving this was reading the code with a practiced eye looking closely at it.  Programmers are always doing this and sometimes even the best need to walk away and clear their minds in order to see the forest thru the trees.

That's why the beginner programmers like me make a big mistake of getting frustrated, angry when something doesn't work although looking badly for the solution of the problem. I couldn't see the forest until now and I yes you're right, need to walk away sometimes to clear my mind instead of drinking another coffee and pushing myself harder to get to it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.