SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question problem with contact form mailing with php

    Hi all, i just registered since i cant resolve this myself and im on a really tight schedule.

    anyway im building this website and i've got the form as follows

    HTML Code:
    <form id="form1"  action="contact.php" method="post">
    						<div class="success"> Contact form submitted!<br><strong>We will be in touch soon.</strong> </div>
    						<fieldset>
    							<label class="name">
    								<input type="text" value="Name:">
    								<span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span> </label>							
    							<label class="email">
    								<input type="email" value="E-mail:">
    								<span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span> </label>
    							<label class="phone">
    								<input type="tel" value="Phone:">
    								<span class="error">*This is not a valid phone number.</span> <span class="empty">*This field is required.</span> </label>
    							<label class="message">
    								<textarea>Message:</textarea>
    								<span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>							
    							<div class="btns und"><a href="#" class="btn" data-type="reset">clear</a><a href="#" class="btn" data-type="submit">submit</a></div>
    						</fieldset>
    					</form>
    and i found this code snippet online but i cant get it to work..
    PHP Code:
    <?php  
    $Name 
    $_REQUEST['name'];  
    $Email $_REQUEST['email'];  
    $Phone $_REQUEST['phone'];  
    $Message $_REQUEST['message'];  

    /*Sending Email*/  

    $to "myemail@mail.com"
    $subject "Question about a service"
    $from $Name
    Name $Name 
    Email 
    $Email  
    Phone 
    $Phone 
    Message 
    $Message
      


    if(
    mail($to$subject$message"From: $from"))  
    echo 
    "Mail sent";  
    else  
    echo 
    "Mail send failure - message not sent";  
    ?>
    i actually think my submit button or link whatever.. isnt doing anything..

    Can anyone please assist me because its driving me crazy..

    yes i tried searching the net and all i can find are different forms with php files but i need to get my form working because of the style used

    thank you all in advance

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Without loading up your stuff and playing trial and error I won't be able to solve it either. But her is my script A to Z for you. Copy and paste http://www.websitecodetutorials.com/...validation.php

    Or if you want a 2 second one here is this one too http://www.websitecodetutorials.com/...ntact-form.php.

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,097
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Hi ic3manbl. Welcome to the forums.

    That's a pretty crummy script you have there. It has no defense against spammers. But one reason it's not working for you is that the HTML inputs are lacking the name="" attribute, which sends information to the PHP script. For example, the first label/input should be something like this:

    Code:
    <label for="username" class="name">
        <input type="text" id="username" name="name" value="Name:">
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  4. #4
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Hi ic3manbl. Welcome to the forums.

    That's a pretty crummy script you have there. It has no defense against spammers. But one reason it's not working for you is that the HTML inputs are lacking the name="" attribute, which sends information to the PHP script. For example, the first label/input should be something like this:

    Code:
    <label for="username" class="name">
        <input type="text" id="username" name="name" value="Name:">
    Yes i fixed that part, forgot it.. but still no luck.. when i click on submit nothing happens at all..

  5. #5
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,097
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by ic3manbl View Post
    Yes i fixed that part
    OK, just to be sure, show us what you have now.

    The next question is: where is contact.php in relation to your contact page? At the moment, it should be in the same folder.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  6. #6
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    OK, just to be sure, show us what you have now.

    The next question is: where is contact.php in relation to your contact page? At the moment, it should be in the same folder.
    I actually fixed it, it was missing onclick(Submit()) now it sends the email and all.. but can i stop it from opening a blank page ? can i instead make it pop an alert window "Mail sent" OK in the existing window

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,097
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by ic3manbl View Post
    it was missing onclick(Submit())
    That's JavaScript, though, which is pretty unreliable. Do you also have a JS file in there?
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  8. #8
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it seems to work now opposed to before using it :/ .. anyway heres the code if it helps:
    HTML Code:
    <form id="form1"  action="contact.php" method="POST">
    						<div class="success"> Contact form submitted!<br><strong>We will be in touch soon.</strong> </div>
    						<fieldset>
    							<label class="name">
    								<input type="text" name="name" value="Name:">
    								<span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span> </label>							
    							<label class="email">
    								<input type="email" name="email" value="E-mail:">
    								<span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span> </label>
    							<label class="phone">
    								<input type="tel" name="phone" value="Phone:">
    								<span class="error">*This is not a valid phone number.</span> <span class="empty">*This field is required.</span> </label>
    							<label class="message" name="message" >
    								<textarea name="message">Message:</textarea>
    								<span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>	
                              <input type="button" value="Submit Form" onclick="submit();">
     
    						</fieldset>
    					</form>
    And the PHP file which i edited for now just to show me if it sent the mail :

    PHP Code:
     <?php 
    $Name 
    $_REQUEST['name']; 
    $Email $_REQUEST['email']; 
    $Phone $_REQUEST['phone']; 
    $Message $_REQUEST['message']; 

    /*Sending Email*/ 

    $to "xxxxxxx@xx.com";
    $subject "Inquiry";
    $from $Email;
    $message =
    "Message from : $Name
      Senders E-Mail : 
    $Email
      Senders Phone Number : 
    $Phone
      
      Message : 
      
    $Message

    "
    ;
    $headers "From: $Email"."\r\n";
    $headers .= 'Cc: xxxxx@xxxxx.com' "\r\n";

    if(
    mail($to$subject$message,$headers))
    echo 
    "Success";
    else echo 
    "Fail"
    ?>

  9. #9
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,097
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    O, right, I didn't notice you were using input type="button". It would be better to use somethng like this:

    Code:
    <input type="submit" value="Submit Form">
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  10. #10
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    FYI you should not even bother getting a script working with no protection. 2 months from now you will only be looking for better once you or your client start getting 100 spams a week. If its worth doing, it's worth doing right.

  11. #11
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,097
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Off Topic:

    Quote Originally Posted by EricWatson View Post
    you should not even bother getting a script working with no protection.
    Yes, a case of "don't say we didn't warn you."
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."


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
  •