Problem sending mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kydude1957
Forum Commoner
Posts: 31
Joined: Sun Sep 14, 2014 1:37 am

Problem sending mail

Post by kydude1957 »

Does anyone see why this would not send mail. I tested another script on my server and it worked. I know the gmail address is fake (did that for posting purposes)

Code: Select all

<?php

if($_POST['submit']){
       if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) {
        $error = 'true';
        
       }  else {
            
            $to = 'testgmail.com'; 
                  
            $name =trim($_POST['name']);
            $email =trim($_POST['email']);
            $message =trim($_POST['comments']);
            
            $subject = "Contact Form";
            
            $messages = "Name: $name \r\n Email: $email \r\n Comments: $comments";
            $headers = "From:" . $name;
            $mailsent = mail($to, $subject, $messages, $headers);
            
            if($mailsent){
                $sent = true;
            }
            
        }
            
        }
    

?>

<!DOCTYPE html PUBLIC "-//WC3/DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtmll-transitional.dtd">
<html xmlns="http://www.w3c.org/1999/xhtml">
<head>
<title>Some Title</title>
<meta http-equiv="content-type" content="text/html" charset="UTF-8" />

<link rel="stylesheet" href="Styles/contact.css" />

</head>

<body>
     <div id="wrapper">
          <h1>Send a Message</h1>
          <?php if($error == true) { ?>
          <p class="error">There was a missing field on the form.  Please make sure you enter all details and a comment</p>
          <?php } if($sent == true) { ?>
          <p class="sent">Thank you for contacting me.  I will do my best to get back to you within 24 hours!!</p>
          <?php } ?>
          <div id="contactform">
          <form name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                <label for="name">Name:</label>
                <input type="text" name="name" />
                <label for="email">Email:</label>
                <input type="text" name="email" />
                <label for="comments">Comments:</label>
                <textarea name="comments" cols="15" rows="10"></textarea>
                <input type="submit" name="submit" class="submit" value="Submit" />
          </form>
          <div style="clear: both;"></div>
          </div>
     </div>

</body>
</html>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Problem sending mail

Post by requinix »

Are you saying you don't see the sent message, or that you do but you don't receive the email?
kydude1957
Forum Commoner
Posts: 31
Joined: Sun Sep 14, 2014 1:37 am

Re: Problem sending mail

Post by kydude1957 »

I dont receive the mail
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem sending mail

Post by Celauran »

As I asked in your other thread about the exact same problem (tsk tsk!), have you confirmed that it is being sent? What do your mail server logs say?
kydude1957
Forum Commoner
Posts: 31
Joined: Sun Sep 14, 2014 1:37 am

Re: Problem sending mail

Post by kydude1957 »

not to be stupid or anything but where are the mail server logs?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem sending mail

Post by Celauran »

Usually in /var/log but you'd need to check your server's configuration to be sure.
kydude1957
Forum Commoner
Posts: 31
Joined: Sun Sep 14, 2014 1:37 am

Re: Problem sending mail

Post by kydude1957 »

Im using godaddy as hosting and i just found out that my plan doesnt let me have access to error logs/
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem sending mail

Post by Celauran »

So check it on your development machine.
Post Reply