SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    May 2007
    Location
    Kent in Uk
    Posts
    538
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why doesnt my contact form mail me?

    Hi

    Some time ago I created a simple form using php. It was set up to mail me when someone had submitted the form. I have noticed recently that it is working in every other way but not mailing me to let know someone has submitted. I have tried and tried to see a problem in the code but to no avail. Can someone help out here?

    This is the code:

    Code:
    <?php require_once("connect/connection.php");
    require_once("includes/functions.php");
    if(isset($_POST['submit'])){
    $errors = array();
    $requiredfields = array('first_name'=> 'Please enter your FIRST NAME','surname'=> 'Please enter your SURNAME','email'=> 'Please enter your E Mail ADDRESS','text'=> 'Please enter your current needs');
    foreach($requiredfields as $fieldname => $requiredfieldsmessage){
    if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname]) || strlen(trim($_POST[$fieldname])) == 0) {
    $errors[] = $requiredfieldsmessage;
    }
    }
     if(count($errors) == 0){
     
     $_POST = array_map('mysqli_prep', $_POST);
     
    $first_name =  mysqli_prep($_POST['first_name']);
    $surname =  mysqli_prep($_POST['surname']);
    $email =   mysqli_prep($_POST['email']);
    $text =  mysqli_prep($_POST['text']);
    $query = "INSERT INTO form (first_name,surname,email,text)Values('{$first_name}','{$surname}','{$email}','{$text}')";
    $result = mysqli_query($connection, $query);
    $message="A contact form has been completed on web-writer-articles.co.uk";
    $subject="Ghostwriter contact form";
    $subject2="Nick Cassells: Ghostwriter and copywriter";
    $message2="Thank you for contacting me concerning your copywriting or ghostwriting needs. I will get back to you at this email address as soon as possible.<br> With best regards,<br> Nick Cassells";
    $email2=$email;
    mail('njc27@sky.com',$subject,$message);
    mail($email2, $subject2, $message2);
    header('Location: brief_return.php');
    exit;
    }
    }
    ?>
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>web writer kent, copywriter and SEO kent</title>
    <meta name="keywords" content="ghostwriter,ghost-writer, writing services, optinise my web site, help me write my book, professional ghost-writer, ghostwriting, how to get my book published, copywriter, web content, articles " />
    <meta name= "description" content= "As a professional web writer I can create text that will make your website fly and get picked up by Google." />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-18301581-5']);
      _gaq.push(['_trackPageview']);
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    
    </script>
    </head>
    
    <body>
    <div id="wrapper">
    <div id="header"><div id="headleft"><img src="myimages/copywriter.jpg" alt="Ghost writer, copyriter, internet marketing for you" title="Ghostwriting, Copywriting and internet marketing. Articles for the web at very reasonable prices. Ask me." />
    </div><!--headleft--><div id="headright"><img src="myimages/writer.jpg" alt="Ghost writer, copyriter, internet marketing for you"  /></div><!--headright-->
    
     <ul class="menu">
                <li><a href="index.php">Home</a></li>
                <li><a href="webcontentservices.php">Web Content</a></li>
                <li><a href="thisisme.php">About me </a></li>
                <li><a href="ghost_writer.php">Ghostwriter</a></li>
                <li><a href="http://www.web-writer-articles.co.uk/blog/">SEO Guide</a></li>
                <li><a href="contact.php">Contact me</a></li>
            </ul>
    </div><!--header-->
    <div id="mainNav">
    <img src="myimages/websitecontent.jpg" alt="Do you need to hire a ghost writer?" width="158" height="789" />
    </div><!--mainNav-->
    <div id="content">
    <div id="mainContent">
    <div id="contactform"><?php
    if(count($errors) != 0){ 
    echo '<h3>Sorry, please address the following errors:-</h3>';
    echo '<ul>'; 
    foreach ($errors as $error) { 
    echo '<li>' . $error . '</li>';}echo '</ul>';
    }
    ?><h3 class="contacttext">For a consultation about your manuscript or a website review for all Intetnet web content needs please contact me. I look forward to hearing from you!</h3>
    <p class="contacttext">Telephone: 01795 843184
    <a href="mailto:njc27@sky.com">Email</a>
    or fill in the form below and I will get back to you as soon as possible:</p>
    <form style="padding:15px;" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
    
    <p>First Name:<br/> <input type="text" size="30" name="first_name" value="<?php echo htmlspecialchars($_POST['first_name'],ENT_QUOTES); ?>" id="fname" /></p>
    <p> Surname:<br/><input type="text" size="30" name="surname" value="<?php echo htmlspecialchars($_POST['surname'],ENT_QUOTES); ?>" id="sname" /></p>
    <p>E mail:<br/><input type="text" size="40" name="email" value="<?php echo htmlspecialchars($_POST['email'],ENT_QUOTES); ?>" id="email" /></p>
    <p>How Can I help you?<br/>
      <textarea rows="10" cols="40" name="text"><?php echo htmlspecialchars($_POST['text'],ENT_QUOTES); ?> </textarea></p><br />
      <input type="submit" name="submit" value="Submit " />
    </form>
    </div>
    thank you

  2. #2
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I just tested your script (minus the database parts) and it works fine. Maybe you should look into your mail server and check for any changes recently.

  3. #3
    SitePoint Evangelist
    Join Date
    May 2007
    Location
    Kent in Uk
    Posts
    538
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tom8 View Post
    I just tested your script (minus the database parts) and it works fine. Maybe you should look into your mail server and check for any changes recently.
    Not sure what you mean by this and where I should be looking. the email is pop3 (I think - whatever that means) works perfectly for all other mail. Is there anything else that could specifically gone wrong with the mail server?

    thanks

  4. #4
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If mails were sent ok for other mails I would check the ones on this script and make sure the mails were indeed sent.
    The mail returns TURE if successfully so just update your code like this:

    $error = 0;
    if(!mail('njc27@sky.com',$subject,$message)) $error++;
    if(!mail($email2, $subject2, $message2)) $error++;
    if($error) echo "Error sending mail";
    else header('Location: brief_return.php');

  5. #5
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your not setting a 'from' header in your mails, some servers will not send mail unless a valid 'from' adress is set. See the php documentation on 'mail'
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  6. #6
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It's worth a try.

    As I have noted, it works for me. You can try it out yourself:
    http://w-cms.org/test/mail.php

    Here is the code:
    PHP Code:
    <?php
       
    //require_once("connect/connection.php");
       //require_once("includes/functions.php");
       
    if(isset($_POST['submit'])){
           
    $errors = array();
           
    $requiredfields = array('first_name'=> 'Please enter your FIRST NAME',
                       
    'surname'=> 'Please enter your SURNAME',
                       
    'email'=> 'Please enter your E Mail ADDRESS',
                       
    'text'=> 'Please enter your current needs');
           foreach(
    $requiredfields as $fieldname => $requiredfieldsmessage)
           {
               if(!isset(
    $_POST[$fieldname]) || empty($_POST[$fieldname]) || strlen(trim($_POST[$fieldname])) == 0)
               {
                   
    $errors[] = $requiredfieldsmessage;
               }
           }
           if(
    count($errors) == 0)
           {
     
               
    //$_POST = array_map('mysqli_prep', $_POST);
     
               
    $first_name =  $_POST['first_name'];
               
    $surname =  $_POST['surname'];
               
    $email =   $_POST['email'];
               
    $text =  $_POST['text'];
               
    //$query = "INSERT INTO form (first_name,surname,email,text)Values('{$first_name}','{$surname}','{$email}','{$text}')";
               //$result = mysqli_query($connection, $query);
               
    $message="A contact form has been completed on web-writer-articles.co.uk";
               
    $subject="Ghostwriter contact form";
               
    $subject2="Nick Cassells: Ghostwriter and copywriter";
               
    $message2="Thank you for contacting me concerning your copywriting or ghostwriting needs. I will get back to you at this email address as soon as possible.<br> With best regards,<br> Nick Cassells";
               
    $email2=$email;
               
    $errors 0;
               if(!
    mail($email,$subject,$message)) $errors++;
               if(!
    mail($email2$subject2$message2)) $errors++;
               if(
    $errors)
               {
                   echo 
    "Error sending mail";
               }
               else
               {
               
    //header('Location: brief_return.php');
                   
    echo "Email sent!";
               }
               exit;
           }
       }
    ?>
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>web writer kent, copywriter and SEO kent</title>
    <meta name="keywords" content="ghostwriter,ghost-writer, writing services, optinise my web site, help me write my book, professional ghost-writer, ghostwriting, how to get my book published, copywriter, web content, articles " />
    <meta name= "description" content= "As a professional web writer I can create text that will make your website fly and get picked up by Google." />
    <link href="style.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
    <div id="wrapper">
    <div id="header"><div id="headleft"><img src="myimages/copywriter.jpg" alt="Ghost writer, copyriter, internet marketing for you" title="Ghostwriting, Copywriting and internet marketing. Articles for the web at very reasonable prices. Ask me." />
    </div><!--headleft--><div id="headright"><img src="myimages/writer.jpg" alt="Ghost writer, copyriter, internet marketing for you"  /></div><!--headright-->

     <ul class="menu">
                <li><a href="#index.php">Home</a></li>
                <li><a href="#webcontentservices.php">Web Content</a></li>
                <li><a href="#thisisme.php">About me </a></li>
                <li><a href="#ghost_writer.php">Ghostwriter</a></li>
                <li><a href="#http://www.web-writer-articles.co.uk/blog/">SEO Guide</a></li>
                <li><a href="#contact.php">Contact me</a></li>
            </ul>
    </div><!--header-->
    <div id="mainNav">
    <img src="myimages/websitecontent.jpg" alt="Do you need to hire a ghost writer?" width="158" height="789" />
    </div><!--mainNav-->
    <div id="content">
    <div id="mainContent">
    <div id="contactform">
    <?php
       
    if(count($errors) != 0){ 
           echo 
    '<h3 style="color:red">Sorry, please address the following errors:-</h3>';
           echo 
    '<ul>'
           foreach (
    $errors as $error) { 
               echo 
    '<li>' $error '</li>';}echo '</ul>';
       }
    ?>
    <h3 class="contacttext">For a consultation about your manuscript or a website review for all Intetnet web content needs please contact me. I look forward to hearing from you!</h3>
    <p class="contacttext">Telephone: xxx xxx xxxx
    <a href="#mailto:njc27@sky.com">Email</a>
    or fill in the form below and I will get back to you as soon as possible:</p>
    <form style="padding:15px;" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >

    <p>First Name:<br/> <input type="text" size="30" name="first_name" value="<?php echo htmlspecialchars($_POST['first_name'],ENT_QUOTES); ?>" id="fname" /></p>
    <p> Surname:<br/><input type="text" size="30" name="surname" value="<?php echo htmlspecialchars($_POST['surname'],ENT_QUOTES); ?>" id="sname" /></p>
    <p>E mail:<br/><input type="text" size="40" name="email" value="<?php echo htmlspecialchars($_POST['email'],ENT_QUOTES); ?>" id="email" /></p>
    <p>How Can I help you?<br/>
      <textarea rows="10" cols="40" name="text"><?php echo htmlspecialchars($_POST['text'],ENT_QUOTES); ?> </textarea></p><br />
      <input type="submit" name="submit" value="Submit " />
    </form>
    </div>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •