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
    541
    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 10: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,252
    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.
    Rick Trethewey
    Rainbo Design

  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,252
    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.
    Rick Trethewey
    Rainbo Design

  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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.17088 seconds
  • Memory Usage 2,987KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (7)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (14)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (14)postbit
  • (14)postbit_onlinestatus
  • (14)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates