Jump to content

Form to Mail


jalen

Recommended Posts

  • Replies 78
  • Created
  • Last Reply

madtechie,

 

this code works on my hosting site:

but not local environment, on local environment i always get this error:

 

 

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Apache\htdocs\FormToEmail.php on line 89

failed

 


<html>

<head>

<title>Untitled 2</title>
</head>

<body>

<form action="FormToEmail.php" method="post">
<table border="1" bgcolor="#ececec" cellspacing="5">
<tr><td>Email address</td><td><input type="text" size="30" name="my_email"></td></tr>
<tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
<tr><td>Email address</td><td><input type="text" size="30" name="email"></td></tr>
<tr><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr>
<tr><td> </td><td><input type="submit" value="Send"><font face="arial" size="1">  <a href="http://FormToEmail.com">Form Mail</a> by FormToEmail.com</font></td></tr>
</table>
</form>

</body>
</html>



<?php

ini_set("display_errors", "1");
error_reporting(E_ALL);


$my_email = '[email protected]';



$errors = array();


// Check for a blank form.

//function recursive_array_check_blank($element_value)
function blank($fillin)
{
//is_array — Finds whether a variable is an array
global $set;
if(!is_array($fillin)){
	if(!empty($fillin)){
		$set = 1;
	}
}else{
foreach($fillin as $value){
	if($set){
		break;
	} blank($value);
}
}
}

blank($_REQUEST);

if(!$set){
$errors[] = "You cannot send a blank form";
}


unset($set);

// Display any errors and exit if errors exist.


if(count($errors)){
foreach($errors as $value){
	print "$value<br>";
} exit;
}







// Build message.

function Comment_text($request_input){
if(!isset($message_output)){
	$message_output ="";
}
			if(!is_array($request_input)){
			$message_output = $request_input;
		}else{
			foreach($request_input as $key => $value){
				if(!empty($value)){
					if(!is_numeric($key)){
						$message_output .= str_replace("_"," ",ucfirst($key)).": ".Comment_text($value).PHP_EOL.PHP_EOL;
						}else{
						$message_output .= Comment_text($value).", ";
					}
				}
			}
		}return rtrim($message_output,", ");
}

$message = Comment_text($_REQUEST);

$message = stripslashes($message);

$subject = "Comment have been added to your YYTgen contribution report!";

$headers = "From: " . $_REQUEST['email'];

if (mail($my_email,$subject,$message,$headers))
{
echo "sent";
}else{
echo "failed";
}

?>

<html>

<head>
<title>Form To Email PHP script from FormToEmail.com</title>
</head>

<body bgcolor="#ffffff" text="#000000">

<div>
<center>
<b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b>
<br>Your message has been sent
</center>
</div>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/160423-form-to-mail/page/4/#findComment-853524
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.