Jump to content

forward email


sdetails

Recommended Posts

Hi

 

I'm having trouble getting this forward email form working, I know the issues but don't really know how to go about them. My php is a bit rusty!

 

1 - I don't know how to submit the form once validated

2 - how do I validate an array, I only need them to enter something into the * Mandatory fields.

 

see attached for the code i'm working with.

 

Thanks in advance!

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/174377-forward-email/
Share on other sites

can you post the code please?

 

 

Simple Send mail syntax>>>>

 

on your form for example:

textbox: email

textbox:Message

action="Sendmail.php"

 

onyour sendmail.php form>>>>

 

 

<?php

  $email = $_REQUEST['email'] ;

  $message = $_REQUEST['message'] ;

 

  mail( "[email protected]", "Your Feedback",

    $message, "From: $email" );

  header( "Location: http://yournextformtoshow.com/next.php" );

?>

 

Link to comment
https://forums.phpfreaks.com/topic/174377-forward-email/#findComment-919208
Share on other sites

Here's the code for both my pages below -

 

<html>
<head>
<title>Recommendation form</title>

</head>
<body topmargin="0" leftmargin="0">


<?
function error_bool($error, $field) {
         if($error[$field]) {
             print("<td style=color:red>");
         }
        else {
            print("<td>");
        }
    }

function show_form() {
global $HTTP_POST_VARS, $print_again, $error, $send;


}
?>

<form  name="tellafriend" method="post" action=" ">

  <p>My details
     
  are:</p>
  <p>
  <?php error_bool($error, "name"); ?>  Name* 
      <input name="name" type="text" id="name" value="<? echo $_POST["name"]; ?>">
<?php error_bool($error, "email"); ?> Email* 
      <input name="email" type="text" id="email" value="<? echo $_POST["email"]; ?>">
</p>
  <p>Email 1*: 
    <input type="text" name="emails[]" id="emails" /> 
    
name 1:* 
<input type="text" name="names[]" id="names" /> 
<br />
Email 2: 
<input type="text" name="emails[]" /> 

name 2: 
<input type="text" name="names[]" /> 
<br />
Email 3: 
<input type="text" name="emails[]" /> 

name 3: 
<input type="text" name="names[]" /> 
<br />
Email 4: 
<input type="text" name="emails[]" /> 

name 4: 
<input type="text" name="names[]" /> 
</p>
  <p>
    <label>
    <textarea name="message" id="message" cols="45" rows="5"></textarea>
    </label>
  </p>
  <p><br />
    
    <input type="submit" name="Submit" value="Submit">
        </p>
</form>


<?

if(isset($_POST["Submit"])) {
    check_form();
} else {
    show_form();
}

function check_email_address($email) {
  // First, we check that there's one @ symbol, and that the lengths are right
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    return false;
  }
  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
     if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
      return false;
    }
  }
  if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
        return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}

function check_form()
{
global $HTTP_POST_VARS, $error, $print_again;
$error['name'] = false;
    if($_POST["name"]=="") {
        $error['name'] = true;
         $print_again = true;
        $message="The name field is empty<br>";
    }
    if(!check_email_address($_POST['email'])) {
        $error['email'] = true;
         $print_again = true;
        $message.="Either Field Empty or Invalid Email ID <br>";
    }
     if($print_again) {
         show_form();
       
       } else {
  
        show_form();
           $message="ok now we can submit, just don't know how too ....";
	       
	   
       }echo "$message";
}

?>

 

 

// submit page

 

<?php


$emailfrom = "[email protected]"; 
$tsubject = "A web page recommendation from";

$headersVar='MIME-Version: 1.0' . "\r\n";
$headersVar .= 'Content-type: text/html;charset=iso-8859-1' . "\r\n";
$headersVar .= 'From: System Admin <[email protected]>' . "\r\n";


// see if the forms been posted
if (isset($_POST) && !empty($_POST)) {
// check for the variable in the post
if (isset($_POST['emails']) && is_array($_POST['emails'])) {

	$names = $_POST['names'];
	$emails = $_POST['emails'];

	$sendername = $_POST['sendername'];
	$message = $_POST['message'];


for ($i = 0; $i < count($emails); $i++) {

$ttext = '
<html>
<head>
  <titletitle</title>
</head>
<body>

  <p>Hi ' . $names[$i] . '! <br> ' . $sendername . 'thought you should check this site out.</p>
  
  <p>' . $message . '</p>
  
  <a href="http://www.google.com">site</a>
  
</body>
</html>
';


@mail("$emails[$i]", $tsubject, $ttext, $headersVar);

}

//echo "Hi" . $sendername . "your messages has been sent!";
}
header('Location: http://www.google.com');

}
?>

Link to comment
https://forums.phpfreaks.com/topic/174377-forward-email/#findComment-919225
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.