Email's not arriving at my email address

Hi guys, I’m a novice when it comes to PHP and I havn’t set up a contact me page before. I’m having issues when i submit the PHP form I’m getting my success message appearing on my web page. But no email appears in my email inbox.

Does anyone out there know how i can fix this problem?

thanks in advance.

Con

<section class="contact-section" id="contact-me">

      <div class="row" id="form">
          <h2 class="form-h2 js--wp-8">
            Contact Me
          </h2>
        </div>
        <div class="row">
            <h3 class="form-h3">
              Have a question or want to work together?
            </h3>
          </div>
    <section class="form-body">
        <form method="post" action="mailer-new.php" class="contact-form" >
          <div class="row">

         <?php
            if ($_GET['success']== 1){
                echo " <div class=\"form-messages success\"> Thank you! your message has been sent. </div>";
            }
            if ($_GET['success']== -1){
                echo " <div class=\"form-messages error\"> Opps there was a problem. Please try again </div>";
            };
          ?>

              <div class="field name-box">
                  <input type="text" name="name" id="name" placeholder="Who Are You?" required/>
                  <label for="name">Name</label>
                  <span class="ss-icon">check</span>
              </div>

              <div class="field email-box">
                  <input type="text" name="email" id="email" placeholder="name@email.com" required/>
                  <label for="email">Email</label>
                  <span class="ss-icon">check</span>
              </div>

              <div class="field msg-box">
                  <textarea name="message" id="msg" rows="4" placeholder="Your message goes here..."/></textarea>
                  <label for="message">Msg</label>
                  <span class="ss-icon">check</span>
              </div>
              <input class="button" type="submit" value="Send"/>
          </div>
      </form>
  </section>
     </section>
<?php // Get the form fields, removes html tags and whitespace. $name = strip_tags(trim($_POST["name"])); $name = str_replace(array("\r","\n"),array(" "," "),$name); $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL); $message = trim($_POST["message"]); // Check the data. if (empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) { header("Location: http://www.conallen.ie/index.php?success=-1#form"); exit; } // Set the recipient email address. Update this to YOUR desired email address. $recipient = "example@example.com"; // Set the email subject. $subject = "New contact from $name"; // Build the email content. $email_content = "Name: $name\n"; $email_content .= "Email: $email\n\n"; $email_content .= "Message:\n$message\n"; // Build the email headers. $email_headers = "From: $name <$email>"; // Send the email. mail($recipient, $subject, $email_content, $email_headers); // Redirect to the index.html page with success code header("Location: http://www.conallen.ie/index.php?success=1#form"); ?>

use a battle-tested mailing library (e.g. SwiftMailer).

Mails from mail() tend to land in Spam (because they often fullfill criteria for spam (like From address not matching the SMTP server)).

1 Like

Hey, thanks for your reply. The messages aren’t appearing in my spam folders. I’m a total beginner with PHP. I’m wondering is there a small error in my code that I’m unaware of. Do you suggest starting from fresh with SwiftMailer?

Cheers

As Dormilich mentioned the mail() function is very limited when it comes to debugging. I highly recommend using a library like Swithmailer that provides more options for sending mail and debugging problems as well. I see you have hard coded URLS in your redirect so it looks like you running this on a remote / host server, correct? In that case mail *should be active but it could be that it isn’t depending on the quality of the host. Again though using a lib with more debug options would help troubleshoot and might eliminate the problem altogether.

hey, thanks for your email. Yeah, this is hosted on a server. Thanks for your recommendations. It appears that the form is submitting correctly but my email address isn’t hooked up to the server. again I’m a complete novice when it comes to PHP, so I’m not too sure what the issue is. I’ll try out the swiftmailer if I cant find the fix. thanks again

I big part of becoming a great engineer is learning to solve problems. Syntax is a very small part and memorization less important than being able to analyze and debug your code and others. The internet today makes it easier than ever to figure these things out on your own.

Thanks

… and when even that fails, there’s SitePoint to help you out, @allenconallen46. We do expect members to make an effort to help themselves, but that doesn’t mean you’re not welcome to ask beginner questions here when you get stuck. Sometimes, it just needs a fresh pair of eyes on your code or a few words of clarification.

2 Likes

I have fixed the issue. The problem wasn’t my code it was with the hosting server. Cheers

2 Likes

On a different note, I’ve just been to your website and notice you have some unparsed PHP code showing above your contact form - looks like you may have accidentally added a closing ?> tag in the middle of your code or something.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.