Jump to content

Form to Mail


jalen

Recommended Posts

  • Replies 78
  • Created
  • Last Reply

here is the code thx

 

 

<form action="FormToEmail.php" method="post">
<table border="1" bgcolor="yellow" 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"></td></tr>
</table>
</form>


<?php


$my_email = "myemail";





$errors = array();



if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}



function recursive_array_check_header($element_value)
{

global $set;

if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);}

}

}

recursive_array_check_header($_REQUEST);

if($set){$errors[] = "You cannot send an email header";}

unset($set);


if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{

if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";}

$_REQUEST['email'] = trim($_REQUEST['email']);

if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

}



if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}



function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

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

unset($set);



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

if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}



function build_message($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)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);


$message = stripslashes($message);

$subject = "FormToEmail Comments";

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

mail($my_email,$subject,$message,$headers);

?>


<html>

<head>
</head>

<body bgcolor="yellow" 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/#findComment-846557
Share on other sites

$my_email = $_POST['my_emai herel'];

 

your form has an input field with the name of "my_email"  and the form method is "post" so when I put

 

$my_email = $_POST['my_email'];

 

That's exactly how it should appear.  I assumed that that's how it should be, seeing as how the variable is coincidentally named the same as the form input field name, and you don't seem to be making use of that field anywhere else in your script... But you are saying you had your physical email there, so I'm going to *assume* that that wasn't the problem to begin with.... right?

Link to comment
https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846581
Share on other sites

To find out why the mail() function call failed (so that you can address the actual problem, rather than guessing), add the following two lines of code (for debugging purposes only, remove them later) immediately after your first opening <?php tag -

 

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

Link to comment
https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846584
Share on other sites

That's exactly how it should appear.  I assumed that that's how it should be, seeing as how the variable is coincidentally named the same as the form input field name, and you don't seem to be making use of that field anywhere else in your script... But you are saying you had your physical email there, so I'm going to *assume* that that wasn't the problem to begin with.... right?

 

yea!

Link to comment
https://forums.phpfreaks.com/topic/160423-form-to-mail/#findComment-846587
Share on other sites

Open your PHP.ini file and check the following

Code: [select]

[mail function]

SMTP = localhost

smtp_port = 25

 

SMTP should be the mail server and the smtp_port should be its port!

 

this is what I have in my php ini for these:

 

[mail function]

; For Win32 only.

SMTP = localhost

smtp_port = 25

 

 

To find out why the mail() function call failed (so that you can address the actual problem, rather than guessing), add the following two lines of code (for debugging purposes only, remove them later) immediately after your first opening <?php tag -

 

Code: [select]

ini_set("display_errors", "1");

error_reporting(E_ALL);

 

 

this is what I have after putting this code at beginning of <?php

 

Notice: Undefined index: myemail in C:\Apache\htdocs\FormToEmail.php on line 82

 

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 196

failed

 

 

 

 

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