Free Web Hosting Forum
(#1 (permalink))
Old
Member
Hans Henrik is on a distinguished road
 
Posts: 57
Join Date: Oct 2011
Location: Norway
Default simple mail() test script! - 11-01-2011, 12:34 PM

here is a simple php mail() function test script i wrote (note that escapeshellcmd() is disabled on 000webhost, and this is a potential security risk, but after talking customer support via ticket, seems they dont care also note this script can not test mb_send_mail() yet, and at 000webhost, mb_send_mail() is also disabled.)
live demo: http://www.hanshenrik.tk/mailtest.php
PHP Code:
<?php
error_reporting
(E_ALL);
//change true/false to edit configs... 
$allow_additional_parameters=true;//allow additional parameters?
$escape_additional_parameters=is_usable('escapeshellcmd') && false;//Escape additional parameters? (its a security thing)
$allow_iniset=is_usable('ini_set') && true;//allow ini_set('sendmail_from') change?
///end of config..
//mailtest v2: added some security configurations and moved result info into <body> (results used to be before <html>)
function is_usable($function) {
  
$disabled_functions_one=explode(',',ini_get('disable_functions'));
  
$disabled_functions_two=explode(', ',ini_get('disable_functions')); //this is for some change between Php4 and 5 with foreach and trim...
if(in_array($function$disabled_functions_one) || in_array($function$disabled_functions_two) || !is_callable($function))
return 
false;
else
return 
true;
}


if(isset(
$_GET['Sto']))
{
//below im using @ instead of tons of isset's... feel free to rewrite it
@$to=$_GET['Sto'];
@
$subject=$_GET['Ssubject'];
@
$message=$_GET['Smessage'];
@
$additional_headers=$_GET['Sadditional_headers'];
@
$additional_parameters=($allow_additional_parameters== true ? ($escape_additional_parameters == true escapeshellcmd($_GET['Sadditional_parameters']) : $_GET['Sadditional_parameters']) : '');
$result_string='';
if(
$allow_iniset && isset($_GET['Ssendmail_from']) && !empty($_GET['Ssendmail_from']))
{
ini_set('sendmail_from',$_GET['Ssendmail_from']);
$result_string.= 'sendmail_from set to: '.ini_get('sendmail_from').'<br/>(Warning: ini_set(\'sendmail_from\') doesnt work on 000webhost for some (unknown to me) reason.)<br/>';
}
$result_string.= 'return of mail() function:';
$result_string.=var_export(
mail($to,$subject,$message,$additional_headers,$additional_parameters),
true);
$result_string.='<br/><br/>';
}


?>
<html><head></head>
<body>
<?php if(isset($result_string)) echo $result_string;?>
a mailtest script.<br/>
php.net documentation: <br/>bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
<br/><br/>
<form name="input" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="get">
$to: <input type="text" name="Sto" /><br/> 
$subject: <input type="text" name="Ssubject" /><br/>
$message: <input type="text" name="Smessage" /><br/>
$additional_headers: <input type="text" name="Sadditional_headers" /> (optional)<br/>
$additional_parameters: <input <?php if(!$allow_additional_parameters) echo 'disabled="true" value="disabled by admin"';?>  type="text" name="Sadditional_parameters" /> (optional<?php if($escape_additional_parameters == true) echo ', warning: will be escaped with <a href="http://no.php.net/manual/en/function.escapeshellcmd.php">escapeshellcmd()</a>'?>)<br/>
ini_set('sendmail_from','input'):<input <?php if(!$allow_iniset) echo 'disabled="true" value="disabled by admin"';?> type="text" name="Ssendmail_from" /> (optional)

<input type="submit" value="Submit" />
</form></body>
</html>


to get my attention, send a private message

Last edited by Hans Henrik; 11-02-2011 at 09:01 PM. Reason: mailtest v2
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
blackdogruns's Avatar
Member
blackdogruns is an unknown quantity at this point
 
Posts: 75
Join Date: Dec 2011
Location: Salem, Oregon
Default 01-13-2012, 03:39 PM

So what was your question?
Reply With Quote
(#3 (permalink))
Old
Member
Hans Henrik is on a distinguished road
 
Posts: 57
Join Date: Oct 2011
Location: Norway
Default 01-13-2012, 03:44 PM

Quote:
Originally Posted by blackdogruns View Post
So what was your question?
question? no question here. just a code snippet i thought may be useful for people to test mail() function.
Quote:
Scripts and Code Snippets
Share useful scripts, applications and code snippets


to get my attention, send a private message
Reply With Quote
(#4 (permalink))
Old
blackdogruns's Avatar
Member
blackdogruns is an unknown quantity at this point
 
Posts: 75
Join Date: Dec 2011
Location: Salem, Oregon
Default 01-13-2012, 05:53 PM

Oh, neat. I was looking at it thinking,"there's nothing wrong with this."
Reply With Quote
(#5 (permalink))
Old
Junior Member
bitmp is on a distinguished road
 
Posts: 1
Join Date: Jan 2012
Default 01-18-2012, 12:26 AM

Is there anything wrong with this code? Are there other settings I need to be aware of :P

<?php
$email = $_POST["email"];
$body = "hahahha";
$subject = "subject";
$header = "header";


mail($email, $subject, $body, $header);



?>
Reply With Quote
(#6 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 6,620
Join Date: Jul 2009
Location: Spain
Default 01-18-2012, 07:37 AM

You should check into the variable is a valid email address:
PHP Code:
<?php 
$email 
$_POST["email"];
echo
"<p>Email content is: $email</p>";
$body "hahahha";
$subject "subject";
$header "header";

mail($email$subject$body$header);

?>
Header also must contain valid data and formatting.


Recuerda realizar copias de seguridad de tus sitios web. Si este mensaje te ayudó puedes pulsar sobre el botón karma
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com