Devilowy Posted August 14, 2014 Share Posted August 14, 2014 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> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 14, 2014 Share Posted August 14, 2014 1 - DON"T bury functions inside your main line code. Keep them separate. 2 - You're losing your content-type string from the message body. Quote Link to comment Share on other sites More sharing options...
Solution fastsol Posted August 14, 2014 Solution Share Posted August 14, 2014 (edited) 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 August 14, 2014 by fastsol Quote Link to comment Share on other sites More sharing options...
Ken_GoDaddy Posted August 14, 2014 Share Posted August 14, 2014 @Devilowy, I am with GoDaddy and came across your post. Did @ginerjm and @fastsol's suggestions work for you? If you still run into issues after trying their suggestions, please feel free to follow up. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 14, 2014 Share Posted August 14, 2014 Why the @ in front of every poster's name? I dont' get it. Quote Link to comment Share on other sites More sharing options...
fastsol Posted August 14, 2014 Share Posted August 14, 2014 Why the @ in front of every poster's name? I dont' get it. On some other forums when you do that it makes a "mention" or something to the like of that for the other posters. Not real useful here, but whatever. Quote Link to comment Share on other sites More sharing options...
Devilowy Posted August 17, 2014 Author Share Posted August 17, 2014 (edited) 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 August 17, 2014 by Devilowy Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 17, 2014 Share Posted August 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
Devilowy Posted August 17, 2014 Author Share Posted August 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 17, 2014 Share Posted August 17, 2014 The longer one looks the simpler the error turns out to be. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.