Not sure what caused your issue but I've "fixed" your code as an example. You should get in the habit of trying to catch error conditions. Also make sure you sanitize your input! For example you don't want some to exploit your script by inserting additional headers as part of the email address. I've included a function that keeps that from happening and more. $fname and $lname should be sanitized if you ever decide to use them in a message header too.
<html>
<head>
<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
}
td {
font-size: x-small;
}
td label {
font-weight: bold;
}
td input[type=text] {
display: block;
margin-left: 0.5em;
width: 90%;
}
table {
width: 460px;
}
</style>
</head>
<body>
<form method="POST" action="testform.php">
<table>
<col width="40%"><col width="60%">
<tr>
<td>
<label for="fname">First Name:</label>
</td>
<td>
<label for="lname">Last Name:</label>
</td>
</tr>
<tr>
<td><input type="text" name="fname" size="15"></Td>
<td><input type="text" name="lname" size="25"></td>
</tr>
<tr>
<td colspan="2">
<label for="email_add">Email Address:</label>
</td>
</tr>
<tr>
<td colspan="2">
<input type="text" name="email_add" size="50">
</td>
</tr>
<tr>
<td style="text-align: left">
<input type="reset" value="Reset" name="Reset">
</td>
<td style="text-align: right">
<input type="submit" value="Submit" name="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>
---------------------------
<?php
// Initialize some variables
// To header value
$msg_recipient = "computerquery@ijpoole.net";
// Subject header value
$msg_subject = "Testform PHP Test";
// Envelope sender
$msg_sender = "computerquery@ijpoole.net";
// Functions used
function validEmail($email) {
/*
Validate an email address.
Provide email address (raw input)
Returns true if the email address has the email
address format and the domain exists.
http://www.linuxjournal.com/article/9585
*/
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex) {
$isValid = false;
}
else {
$domain = substr($email, $atIndex 1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64) {
// local part length exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255) {
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.') {
// local part starts or ends with '.'
$isValid = false;
}
else if (preg_match('/\\.\\./', $local)) {
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.] $/', $domain)) {
// character not valid in domain part
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain)) {
// domain part has two consecutive dots
$isValid = false;
}
else if
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'* ?^{}|~.-]) $/',
str_replace("\\\\","",$local))) {
// character not valid in local part unless
// local part is quoted
if (!preg_match('/^"(\\\\"|[^"]) "$/',
str_replace("\\\\","",$local))) {
$isValid = false;
}
}
if ($isValid && !(checkdnsrr($domain,"MX") ||
checkdnsrr($domain,"A"))) {
// domain not found in DNS
$isValid = false;
}
}
return $isValid;
}
// Process input
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// get posted data into local variables
$email_add = $_POST['email_add'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
// valid input
if ($fname == '' || $lname == '' || $email_add == '') {
$error = 'Invalid input: blank field';
}
if (validEmail($email_add) == false) {
$error = 'Invalid input: invalid address';
}
if ($error === '') {
$msg_headers = "From: $email_add\n";
$params = '-f' . $msg_sender;
$msg_body = "";
$msg_body .= "You have received an order from:\n";
$msg_body .= "\n";
$msg_body .= $fname . " " . $lname . "\n";
$result =
mail(
$msg_recipient,
$msg_subject,
$msg_body,
$msg_headers,
$params
);
if (!$result) {
$error = 'Could not send message.';
}
}
}
else {
$error = 'You did not submit the form correctly.';
}
// Generate output
if ($error === '') {
echo
"$fname $lname< /br>" .
"Your email test completed successfully.";
}
else {
echo
"An error occured:< /br>" .
$error;
}
?>
Customer since 2000
openvein.org