www.webdeveloper.com
Results 1 to 14 of 14

Thread: formmail not sending

  1. #1
    Join Date
    Sep 2012
    Posts
    9

    formmail not sending

    Morning all,

    I wondered if someone could help me please.

    I have created a website with a contact me section. I have used formmail to get the message over to me, but something isn't quite right as it isn't sending. It shows invalid email address.

    I used the same code on another site and it worked perfectly (after some tweaking).

    Is it possible someone could have a look for me and give me some tips?

    The site is www.barrygoddard.com and the contact form is right at the bottom.

    Any help appreciated.

    Thanks!

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    Your email field needs to have a name pre-defined by the formmail.
    Currently you have <input type="text" placeholder="Your email ...">
    which should be:
    <input type="text" name="email" placeholder="Your email ...">
    or
    <input type="text" name="email_address" placeholder="Your email ...">

    You can quickly look into the formmail.php file to see what name is actually used for the email address field.
    It can be email, emailaddress, email_address,... you get the idea.

    By the way the other 2 fields for the visitor's name and the message should also each have a name or you will not receive that data the user has filled out.
    Last edited by holyhttp; 09-14-2012 at 11:48 PM.

  3. #3
    Join Date
    Sep 2012
    Posts
    9
    Hi, thanks for the info. This is what I've got now, but it is still throwing up the same errro?

    <div class="textField"><input type="text" name"name" placeholder="Your name ..." /></div>
    <div class="textField"><input type="text" name="email" placeholder="Your email ..."></div>
    <div class="textField"><textarea cols="20" rows="4" name"message" placeholder="Your message ..."></textarea></div>

    I've checked the formmail.php and I think that is the right names. I've put the whole of the formmail.php file below, but last time I had an issue with formmail it was this line that was causing the problems " if (!ereg("^[-a-z0-9_.]+@[-a-z0-9_]+\.([-a-z0-9_.]+)*[-a-z0-9_.]+$", $email))"

    <!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=UTF-8" />
    <META HTTP-EQUIV="refresh" content="0;URL=http://barrygoddard.com/thanks.html">
    <title>Email Form</title>
    </head>

    <body>
    <?php
    $name=addslashes($_POST['name']);
    $email=addslashes($_POST['email']);
    $comments=addslashes($_POST['message']);

    // you can specify which email you want your contact form to be emailed to here

    $toemail = "MY EMAIL ADDRESS";
    $subject = "From barrygoddard.com";

    $headers = "MIME-Version: 1.0\n"
    ."From: \"".$name."\" <".$email.">\n"
    ."Content-type: text/html; charset=iso-8859-1\n";

    $body = "Name: ".$name."<br>\n"
    ."Email: ".$email."<br>\n"
    ."Comments:<br>\n"
    .$comments;

    if (!ereg("^[-a-z0-9_.]+@[-a-z0-9_]+\.([-a-z0-9_.]+)*[-a-z0-9_.]+$", $email))
    {
    $email_error = "Enter a valid email";
    $send = "no";
    }
    echo "That is not a valid email address. Please return to the"
    ." previous page and try again.";
    exit;

    mail($toemail, $subject, $body, $headers);
    echo "Thanks for submitting your comments";
    ?>
    </body>
    </html>

  4. #4
    Join Date
    Mar 2011
    Posts
    1,147
    You've still got syntax errors in your HTML. Try:
    Code:
    <div class="textField"><input type="text" name="name" placeholder="Your name ..." /></div>
    <div class="textField"><input type="text" name="email" placeholder="Your email ..."></div>
    <div class="textField"><textarea cols="20" rows="4" name="message" placeholder="Your message ..."></textarea></div>
    Those missing "="s matter. Spend some time learning HTML. When you run into trouble, use a validator like http://validator.w3.org/ to check your code for errors - at least until you gain more experience. You'll save yourself a lot of time and grief.

  5. #5
    Join Date
    Sep 2012
    Posts
    9
    Thanks very much. I'll give it a go when I'm home.

    Will look into the validation too. Thanks

  6. #6
    Join Date
    Sep 2012
    Posts
    9
    Hi, tried this in the index.html file, but still getting the same error.

    I added;

    <div class="textField"><input type="text" name="name" placeholder="Your name ..." /></div>
    <div class="textField"><input type="text" name="email" placeholder="Your email ..."></div>
    <div class="textField"><textarea cols="20" rows="4" name="message" placeholder="Your message ..."></textarea></div>

    I think my problem is more to do with the php file not being written as it should be. Any other ideas?

  7. #7
    Join Date
    Sep 2012
    Posts
    9
    I have changed the php file to something more simple. I am now receiving mail, but the fields are blank.

    This is the php;

    Code:
    <?php
    $name = $_POST['cf_name'];
    $email = $_POST['cf_email'];
    $message = $_POST['cf_message'];
    
    $mail_to = 'MY EMAIL ADDRESS';
    $subject = 'an email from barrygoddard.com'.$field_name;
    
    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Message: '.$field_message;
    
    $headers = 'From: '.$field_email."\r\n";
    $headers .= 'Reply-To: '.$field_email."\r\n";
    
    $mail_status = mail($mail_to, $subject, $body_message, $headers);
    
    if ($mail_status) { ?>
    	<script language="javascript" type="text/javascript">
    		window.location = 'thanks.html';
    	</script>
    <?php
    }
    else { ?>
    	<script language="javascript" type="text/javascript">
    		alert('Message failed. Please, send an email to MY EMAIL ADDRESS');
    		window.location = 'index.html';
    	</script>
    <?php
    }
    ?>
    and this is the html;
    Code:
    									<div class="formRow">
    						<div class="textField"><input type="text" name="cf_name" placeholder="Your name ..." /></div>
    						<div class="textField"><input type="text" name="cf_mail" placeholder="Your email ..."></div>
    						<div class="textField"><textarea cols="20" rows="4" name="cf_message" placeholder="Your message ..."></textarea></div>
    									</div>
    									<div class="formRow">
    Any suggestions?

  8. #8
    Join Date
    Mar 2011
    Posts
    1,147
    Change the first three lines of the script to:
    Code:
    <?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    The parameter names here must match the 'name' attribute of your <input> tags in your form.

  9. #9
    Join Date
    Sep 2012
    Posts
    9
    I really appreciate your time on this.

    I've changed the code, but the email is coming through as follows;

    From:
    E-mail:
    Message:

    It is also coming from an unknown sending (which may be the way it is supposed to be).

    Any other thoughts?

  10. #10
    Join Date
    Mar 2009
    Posts
    452
    $field_name = $_POST['cf_name'];
    $field_email = $_POST['cf_email'];
    $field_message = $_POST['cf_message'];

  11. #11
    Join Date
    Sep 2012
    Posts
    9
    Thanks, I was just looking at that.

    I've changed them to;

    $field_name = $_POST['name'];
    $field_email = $_POST['email'];
    $field_message = $_POST['message'];

    Still getting blank messages!

  12. #12
    Join Date
    Sep 2012
    Posts
    9
    Just to confirm, this is the current formmail and html that I am using;

    Code:
    							<div class="formRow">
    						<div class="textField"><input type="text" name="name" placeholder="Your name ..." /></div>
    						<div class="textField"><input type="text" name="email" placeholder="Your email ..."></div>
    						<div class="textField"><textarea cols="20" rows="4" name="message" placeholder="Your message ..."></textarea></div>
    									</div>
    									<div class="formRow">
    										<button class="btnSmall btn submit right">
    											<span>Send Message</span>
    										</button>
    									</div>
    								</fieldset>
    							</form>
    						</div>
    AND

    Code:
    <?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    
    $mail_to = 'MY EMAIL ADDRESS';
    $subject = 'an email from MY EMAIL ADDRESS'.$field_name;
    
    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Message: '.$field_message;
    
    $headers = 'From: '.$field_email."\r\n";
    $headers .= 'Reply-To: '.$field_email."\r\n";
    
    $mail_status = mail($mail_to, $subject, $body_message, $headers);
    
    if ($mail_status) { ?>
    	<script language="javascript" type="text/javascript">
    		window.location = 'thanks.html';
    	</script>
    <?php
    }
    else { ?>
    	<script language="javascript" type="text/javascript">
    		alert('Message failed. Please, send an email to MY EMAIL ADDRESS');
    		window.location = 'index.html';
    	</script>
    <?php
    }
    ?>

  13. #13
    Join Date
    Mar 2009
    Posts
    452
    another thing to make sure: are your fields inside a form and the method is set to POST for this form

  14. #14
    Join Date
    Sep 2012
    Posts
    9
    Thanks, i've added the method to be post and it is within a form (and the form closes), but still getting blank messages.

    Code:
    							<form action="THE LOCATION OF MY PHP FILE" class="form" id="formmail" method="post">

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles