Link to home
Start Free TrialLog in
Avatar of park6469
park6469

asked on

Confirmation Email - Variable in a PHP mail function?

Hi all! I'm having a strange issue with this code:

<?php

$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

session_start();
if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) {
mail("administrator@domain.com","Signup Request","Customer Data:

Company: " . $_POST['field_1'] . "
Contact Name: " . $_POST['field_2'] . "
Address: " . $_POST['field_3'] . "
City: " . $_POST['field_4'] . "
State: " . $_POST['field_5'] . "
ZIP: " . $_POST['field_6'] . "
Phone Number: " . $_POST['field_7'] . "
E-Mail Address: " . $_POST['field_8'] . "
\nAccount Number: " . $_POST['field_9'] . "
", "From: Web Form");

mail("$customer","Signup Request has been received.","Hello,

This is a confirmation email to notify you that your submission has been received ans is being reviewed by our staff. Please allow up to 3 business days for review.

Thank you.");

include("confirm.html");
}
else {
echo "You did not enter the correct code in the bottom of the form. Please <a href='form.html'>go back</a> and try again.";
}

?>

Open in new window


The problem is that the second function needs to pull field_8 from the form and send the submitter an email letting them know their email was received.

I can't for the life of me figure out how to make it happen.

Other than that the file works fine. I had been trying this:

mail("$_POST['field_8']"   .   .   .   .   .   .   .   

Open in new window


But it's not working, I get:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/**********/public_html/signup/processor.php on line 20
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Below is my PHP demo email form.  Save it as "Email.php".  It posts to itself so you can just put in your own email address and see it work.

You code above doesn't have any 'header' information which is required by most SMTP servers to process your mail.  It is also checked by the receiving email server and the spam checker they have.  You will probably have trouble without it.  Look at the header info in my code to see what I'm talking about.
<?php
# some settings of POST vars
if (!isset($_POST['send']))  $send = ''; else $send = $_POST['send'];
if (!isset($_POST['toText'])) $toText = ''; else $toText = $_POST['toText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['subjectText'])) $subjectText = ''; else $subjectText = $_POST['subjectText'];
if (!isset($_POST['msgText'])) $msgText = ''; else $msgText = $_POST['msgText'];
if (!isset($_POST['ccText'])) $ccTexth = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['bccText'])) $bccText = ''; else $bccText = $_POST['bccText'];
if (!isset($_POST['nameText'])) $nameText = ''; else $nameText = $_POST['nameText'];
if (!isset($_POST['fromText'])) $fromText = ''; else $fromText = $_POST['fromText'];

if ($send == "") {
    $title="Test Email Page";
    $announce="---";
}
else {
	if($fromText === "") die("No name!");
  $toText="youremail@yourdomain.com";
	$title="Test Email Page";
  $announce="Your Message has been Sent!";
	$header = "From: ".$fromText."\r\n";
//	$header .= "Cc: ".$ccText."\n";
	$header .= "Reply-To : ".$fromText."\r\n";
	$header .= "Return-Path : ".$fromText."\r\n";
	$header .= "X-Mailer: PHP\r\n";
	$header .= "MIME-Version: 1.0\r\n";
	$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
//	ini_set(sendmail_from,$fromText);  
	mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);
//	ini_restore(sendmail_from);
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo($title)?></title>
<style type="text/css">
<!-- 
A:link { color: #999999; }
A:visited { color: #999999; }
A:hover {color: #0099ff;}
-->
</style>
<script type="text/javascript">
<!--
function check()
{
var at=document.getElementById("fromText").value.indexOf("@");
var eml=document.getElementById("fromText").value;
var nam=document.getElementById("nameText").value;
var alerttxt="";
var submitOK="true";

if (eml.length < 5 || at == -1)
    {
    alerttxt=alerttxt+"Please enter a valid e-mail address!\r\n";
    submitOK="false"
    //return false;
    }
if (nam.length < 5)
    {
    alerttxt=alerttxt+"Please enter your name.\r\n";
    submitOK="false"
    //return false;
    }
if (nam != "aaron")
    {
    alerttxt=alerttxt+"Please enter your name.\r\n";
    submitOK="false"
    //return false;
    }
if (submitOK=="false")
    {
    alert(alerttxt);
    return false;
    }

}

// -->
</script>
</head>

<body bgcolor="#ddeedd">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" summary="" width="580">
<tr><td align="center">

<?php
if ($send != "") {
   	echo ("To: ".$toText."<br>\r\nSubject: ".$subjectText."<br>\r\n".$msgText."<br>\r\n".$header);
		}
?>

<p><b><font color="#000000" size="5">Test Email</font></b></p>
<font size="4" color="#000000">

<!--   <form method="POST" action="<?php echo($PHP_SELF)?>"> -->
  <form method="POST" action="Email.php" onsubmit="return check();">
    <p><font size="3"><b>Name: <input type="text" name="nameText" id="nameText" size="46"></b></font></p>
    <p><font size="3"><b>Email: <input type="text" name="fromText" id="fromText" size="46"></b></font></p>
    <input type="hidden" name="subjectText" value="Web Mail">
    <p><font face="Arial" size="3"><b>Message Text:</b></font></p>
    <p><font face="Arial" size="3"><b><textarea rows="6" name="msgText" cols="60"></textarea></b></font></p>
    <p><font size="3"><b><input type="submit" value="Send" name="send" style="font-family: Arial; font-size: 12pt; font-weight: bold"></b></font></p>
    <input type="hidden" name="state" value="1">
  </form>
  <b><font face="Arial" size="4" color="#e00000"><?php echo($announce)?></font></b><br><br>

</font>
</td></tr>
</table> 
</div>


</body>
</html>

Open in new window

Avatar of park6469
park6469

ASKER

Not quite the answer I am looking for. Disregarding headers, I need that form_8 variable to be passed into a second mail function to email the form submitter letting them know it's been received.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The PHP docs http://us2.php.net/manual/en/function.mail.php say you can put multiple recipients on the same line if you want them to get the same message.  I would do it like this:
$to = $_POST['field_8'].','.$customer;
mail($to,"Signup Request has been received.","Hello,...

Open in new window