+ Reply to Thread
Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By ammoknig

Thread: Php form wont email

  1. #1
    ammoknig is offline x10Hosting Member ammoknig is an unknown quantity at this point
    Join Date
    Jan 2012
    Posts
    3

    Php form wont email

    Please help!!!! I need to set up this form for email. New to php.

    PHP Code:
    <?php
    if(isset($_POST['email'])) {
         
        
    // EDIT THE 2 LINES BELOW AS REQUIRED
        
    $email_to "****@***.com";
        
    $email_subject "Test";
         
         
        function 
    died($error) {
            die();
        }
         
        
    // validation expected data exists
        
    if(!isset($_POST['first_name']) ||
            !isset(
    $_POST['last_name']) ||
            !isset(
    $_POST['email']) ||
            !isset(
    $_POST['telephone']) ||
            !isset(
    $_POST['comments'])) {
            
    died('We are sorry, but there appears to be a problem with the form you submitted.');       
        }
         
        
    $first_name $_POST['first_name']; // required
        
    $last_name $_POST['last_name']; // required
        
    $email_from $_POST['email']; // required
        
    $telephone $_POST['telephone']; // not required
        
    $comments $_POST['comments']; // required
         
        
    $error_message "";
        
    $email_exp '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!
    preg_match($email_exp,$email_from)) {
        
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
        
    $string_exp "/^[A-Za-z .'-]+$/";
      if(!
    preg_match($string_exp,$first_name)) {
        
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
      }
      if(!
    preg_match($string_exp,$last_name)) {
        
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
      }
      if(
    strlen($comments) < 2) {
        
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      }
      if(
    strlen($error_message) > 0) {
        
    died($error_message);
      }
        
    $email_message "Form details below.\n\n";
         
        function 
    clean_string($string) {
          
    $bad = array("content-type","bcc:","to:","cc:","href");
          return 
    str_replace($bad,"",$string);
        }
         
        
    $email_message .= "first Name: ".clean_string($first_name)."\n";
        
    $email_message .= "last Name: ".clean_string($last_name)."\n";
        
    $email_message .= "email: ".clean_string($email_from)."\n";
        
    $email_message .= "telephone: ".clean_string($telephone)."\n";
        
    $email_message .= "comments: ".clean_string($comments)."\n";
         
         
    // create email headers
    $headers 'From: '.$from."\r\n".
    'X-Mailer: PHP/' phpversion();
    mail($email_to$email_subject$email_message$headers);  
    ?>
     
    <!-- include your own success html here -->
     
    Thank you for contacting us. We will be in touch with you very soon.
     
    <?php
    }
    ?>


    HTML Code:
    <!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>
    	<!-- Start WOWSlider.com HEAD section -->
    	<link rel="stylesheet" type="text/css" href="engine1/style.css" media="screen" />
    	<style type="text/css">a#vlb{display:none}</style>
    	<script type="text/javascript" src="engine1/jquery.js"></script>
    	<script type="text/javascript" src="engine1/wowslider.js"></script>
    	<!-- End WOWSlider.com HEAD section -->
    	<script type="text/javascript" src="Javascript/Dropdown.js"></script>
        <link rel="stylesheet" type="text/css" href="CSS/CSS.css" />
        <script type="text/javascript">
    		function clearText(field){
    			if(field.defaultValue == field.value) field.value = "";
    			else if(field.value == "") field.value = field.defaultValue;
    		}
    	</script>
    <title>****** - Home - Testimonials</title>
    
    
    
    
    </head>
    
    <body>
    <div id="container">
    	<div id="topnav">
           	<ul class="topnav">
               	<li style="padding-left: 40px;"><a href="Index.html">Home</a>
                	<!--ul class="subnav" style="display: none;">
                        <li><a href="#">Calender</a></li>
                    </ul-->
                </li>
                <li><a href="Home/Testimonials.html">Testimonials</a></li>
                <li><a href="#">Robo Camp 2012</a></li>
                <li><a href="#">About FIRST</a>
                	<ul class="subnav" style="display: none;">
                    	<li><a href="#">About FIRST</a></li>
                    	<li><a href="#">BREAKAWAY</a></li>
                        <li><a href="#">Chief Delphi</a></li>
                        <li><a href="http://www.usfirst.org/">US First</a></li>
                    </ul>
                </li>
                <li><a href="#">About 1566</a>
                	<ul class="subnav" style="display: none;">
                    	<li><a href="#">About 1566</a></li>
                        <li><a href="#">Awards</a></li>
                        <li><a href="#">Members</a></li>
                        <li><a href="#">Mentors</a></li>
                        <li><a href="#">Team Organization</a></li>
                    </ul>
                </li>
                <li><a href="#">Our robots</a></li>
                <li><a href="#">Media</a>
                   	<ul class="subnav" style="display: none; ">
                        <li><a href="#">News Articles</a></li>                      
                        <li><a href="Media/Pictures.html">Pictures</a></li>
                        <li><a href="#">Videos</a></li>
                    </ul>
              	</li>
                <li><a href="#">Contact Us</a></li>
                <li><a href="#">Community Outreach</a></li>
                <li><a href="#">Get Involved</a></li>
                <li><a href="#">Sponsors</a></li>
            </ul>
       	</div>     
        <!--Start of body Text-->
        <div id="body_container">
        	<div id="body_no_slider">
    	    	<center><h1><i>Contact US</i></h1></center><br />
                		<form name="contactform" method="post" action="PHP/send_form_email.php">
    				<table width="450px">
    					<tr>
     						<td valign="top">
      							<label for="first_name">First Name *</label>
     						</td>
     						<td valign="top">
      							<input  type="text" name="first_name" maxlength="50" size="30">
     						</td>
    					</tr>
    					<tr>
     						<td valign="top">
     							 <label for="last_name">Last Name *</label>
     						</td>
     						<td valign="top">
      							<input  type="text" name="last_name" maxlength="50" size="30">
     						</td>
    					</tr>
    					<tr>
    			 			<td valign="top">
      							<label for="email">Email Address *</label>
     						</td>
     						<td valign="top">
      							<input  type="text" name="email" maxlength="80" size="30">
     						</td>
    					</tr>
    					<tr>
     						<td valign="top">
      							<label for="telephone">Telephone Number</label>
     						</td>
     						<td valign="top">
      							<input  type="text" name="telephone" maxlength="30" size="30">
     						</td>
    					</tr>
    					<tr>
     						<td valign="top">
      							<label for="comments">Comments *</label>
    						</td>
     						<td valign="top">
      							<textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
     						</td>
    					</tr>
    					<tr>
     						<td colspan="2" style="text-align:center">
      							<input type="submit" value="send">
     						</td>	
    					</tr>
    				</table>
    			</form>
            </div>
    	</div>
        	<!--End of body Text-->
        <div id="body_bg_bottom"></div>
        <div id="footer">
        	<div id="text">
     	    Designed by </div>
        </div>
    </div>
    </body>
    </html>

  2. #2
    cybrax's Avatar
    cybrax is offline x10 Elder cybrax is on a distinguished road
    Join Date
    Aug 2009
    Location
    UK
    Posts
    699

    Re: Php form wont email

    Variable $from is not defined, all outgoing messages from the server must use a valid email address

    PHP Code:
    // create email headers
    $headers 'From: '.$from."\r\n".
    'X-Mailer: PHP/' phpversion();
    mail($email_to$email_subject$email_message$headers); 
    try this.. using your own email address!
    PHP Code:
    // create email headers
    $from 'me@myX10hostedsite.com';

    $headers 'From: '.$from."\r\n".
    'X-Mailer: PHP/' phpversion();
    mail($email_to$email_subject$email_message$headers); 
    The code must flow.
    Project 157: Latest UK Jobs direct to your mobile phone
    New Domain under construction: Lovelogic.net
    home for some new projects that we can't keep here ;)


  3. #3
    ammoknig is offline x10Hosting Member ammoknig is an unknown quantity at this point
    Join Date
    Jan 2012
    Posts
    3

    Re: Php form wont email

    PHP Code:
    <?php
    if(isset($_POST['email'])) {
         
        
    // EDIT THE 2 LINES BELOW AS REQUIRED
        
    $email_to 'webmaster@ammoknig.x10.mx';
        
    $email_subject "Robotics Form Test";
         
         
        function 
    died($error) {
            die();
        }
         
        
    // validation expected data exists
        
    if(!isset($_POST['first_name']) ||
            !isset(
    $_POST['last_name']) ||
            !isset(
    $_POST['email']) ||
            !isset(
    $_POST['telephone']) ||
            !isset(
    $_POST['comments'])) {
            
    died('We are sorry, but there appears to be a problem with the form you submitted.');       
        }
         
        
    $first_name $_POST['first_name']; // required
        
    $last_name $_POST['last_name']; // required
        
    $email_from $_POST['email']; // required
        
    $telephone $_POST['telephone']; // not required
        
    $comments $_POST['comments']; // required
         
        
    $error_message "";
        
    $email_exp '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!
    preg_match($email_exp,$email_from)) {
        
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
        
    $string_exp "/^[A-Za-z .'-]+$/";
      if(!
    preg_match($string_exp,$first_name)) {
        
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
      }
      if(!
    preg_match($string_exp,$last_name)) {
        
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
      }
      if(
    strlen($comments) < 2) {
        
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      }
      if(
    strlen($error_message) > 0) {
        
    died($error_message);
      }
        
    $email_message "Form details below.\n\n";
         
        function 
    clean_string($string) {
          
    $bad = array("content-type","bcc:","to:","cc:","href");
          return 
    str_replace($bad,"",$string);
        }
         
        
    $email_message .= "first Name: ".clean_string($first_name)."\n";
        
    $email_message .= "last Name: ".clean_string($last_name)."\n";
        
    $email_message .= "email: ".clean_string($email_from)."\n";
        
    $email_message .= "telephone: ".clean_string($telephone)."\n";
        
    $email_message .= "comments: ".clean_string($comments)."\n";
         
         
    // create email headers
    $from 'webmaster@ammoknig.x10.mx';

    $headers 'From: '.$from."\r\n".
    'X-Mailer: PHP/' phpversion();
    mail($email_to$email_subject$email_message$headers);  
    ?>
     
    <!-- include your own success html here -->
     
    Thank you for contacting us. We will be in touch with you very soon.
     
    <?php
    }
    ?>
    I changed what you said, but it still doesn't work???

  4. #4
    surganda49 is offline x10Hosting Member surganda49 is an unknown quantity at this point
    Join Date
    Sep 2010
    Posts
    11

    Re: Php form wont email

    what is the error message you get ?

  5. #5
    ammoknig is offline x10Hosting Member ammoknig is an unknown quantity at this point
    Join Date
    Jan 2012
    Posts
    3

    Re: Php form wont email

    There is no error message.
    yarlpavanan81 likes this.

  6. #6
    yarlpavanan81's Avatar
    yarlpavanan81 is offline x10Hosting Member yarlpavanan81 is an unknown quantity at this point
    Join Date
    Jun 2011
    Location
    mathagal, jaffna, northern province, sri lanka
    Posts
    34

    Re: Php form wont email

    Good guidance

  7. #7
    mjaoune5571 is offline x10Hosting Member mjaoune5571 is an unknown quantity at this point
    Join Date
    Oct 2011
    Posts
    14

    Re: Php form wont email

    MSN mails,Yahoo mails, and Google mails don't receive messages that are sent using php mail function, so create an email in your server, and let it receive the sent emails.

    Best,
    MJaoune

  8. #8
    articmonkey123029 is offline x10Hosting Member articmonkey123029 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    11

    Re: Php form wont email

    when I created mine, I found out some emails black list emails being sent from certain free domains. There is some software (don't have it on hand at the moment) that allows you to create forms and link them to your website allowing emails to smoothly be sent to users. Try google see what comes up .

+ Reply to Thread

Similar Threads

  1. My email wont work
    By tropicalfishforums34 in forum Free Hosting
    Replies: 1
    Last Post: 12-16-2011, 12:35 PM
  2. PHP Form Scrip - Not forwarding form information to email...
    By nd.walleye42 in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 12-16-2011, 01:34 AM
  3. conformation email wont send
    By g00s3 in forum Free Hosting
    Replies: 2
    Last Post: 04-18-2010, 11:28 PM
  4. Email wont work..
    By newtony in forum Free Hosting
    Replies: 0
    Last Post: 10-22-2008, 11:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers