Php form wont email

ammoknig

New Member
Messages
3
Reaction score
0
Points
0
Please help!!!! I need to set up this form for email. New to php.

PHP:
<?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:
<!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>
 

cybrax

Community Advocate
Community Support
Messages
764
Reaction score
27
Points
0
Variable $from is not defined, all outgoing messages from the server must use a valid email address

PHP:
// 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:
// create email headers
$from = 'me@myX10hostedsite.com';

$headers = 'From: '.$from."\r\n".
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
 

ammoknig

New Member
Messages
3
Reaction score
0
Points
0
PHP:
<?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???
 

mjaoune5571

New Member
Messages
13
Reaction score
0
Points
0
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
 

articmonkey123029

New Member
Messages
14
Reaction score
0
Points
0
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 :).
 
Top