Jump to content

php form problem


raytz

Recommended Posts

hi,

I am new to php and i got a script from stronghtml regarding simple form to email. everything seems to work but the email is not recieved. Please can anyone help. here is the script.

[code]
<!-- Created with <STRONG><CONTACT> -->
<!-- http://www.stronghtml.com/ -->

<?php
function valid_email($mail) {
$user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+';
$domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+';
$ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}';
$ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}';
return preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail);
}
if (isset($_POST['contactformvar3'])) $contactformvar3=trim($_POST['contactformvar3']); else $contactformvar3="";
if (isset($_POST['contactformvar4'])) $contactformvar4=trim($_POST['contactformvar4']); else $contactformvar4="";
if (isset($_POST['contactformvar5'])) $contactformvar5=$_POST['contactformvar5']; else $contactformvar5="";
if (isset($_POST['contactformseen'])) $contactformseen="y"; else $contactformseen="n";
$contactformform='
<form name="contactform" method="post" action="">
<input type="hidden" name="contactformseen" value="y">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right" valign="middle" class="contactformLeftColumn">Full name</td>
<td align="left" class="contactformRightColumn"><input name="contactformvar3" id="contactformvar3" type="text" class="contactformTextField" value="'.$contactformvar3.'"></td>
</tr>
<tr>
<td align="right" valign="middle" class="contactformLeftColumn">email</td>
<td align="left" class="contactformRightColumn"><input name="contactformvar4" id="contactformvar4" type="text" class="contactformTextField" value="'.$contactformvar4.'"></td>
</tr>
<tr>
<td align="right" valign="top" class="contactformLeftColumn">comments</td>
<td align="left" class="contactformRightColumn"><textarea name="contactformvar5" id="contactformvar5" class="contactformTextArea">'.$contactformvar5.'</textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="Submit" value="Submit" class="contactformSubmit"></td>
</tr>
</table>
</form>';
if($contactformseen!="y") {
print "$contactformform";
} else {
$errstr="";
if (strlen($contactformvar3)<0) {
$errstr.="Full name value must be at least 0 character.<br>";
}
if (strlen($contactformvar3)>100) {
$errstr.="Full name value must not exceed 100 characters.<br>";
}
if (strlen($contactformvar4)<0) {
$errstr.="email value must be at least 0 character.<br>";
}
if (strlen($contactformvar4)>50) {
$errstr.="email value must not exceed 50 characters.<br>";
}
if (!valid_email($contactformvar4)) {
$errstr.="You entered an invalid email value.<br>";
}
if (strlen($contactformvar5)<0) {
$errstr.="comments value must be at least 0 character.<br>";
}
if (strlen($contactformvar5)>500) {
$errstr.="comments value must not exceed 500 characters.<br>";
}
if ($errstr!='') {
print '<div align="center" class="contactformErrors">';
print $errstr;
print '</div>';
print $contactformform;
} else {
if (isSet($_SERVER)) {
if (isSet($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isSet($_SERVER['HTTP_CLIENT_IP'])) {
$realip = $_SERVER['HTTP_CLIENT_IP'];
} else {
$realip = $_SERVER['REMOTE_ADDR'];
}
} else {
if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
$realip = getenv( 'HTTP_X_FORWARDED_FOR' );
} elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
$realip = getenv( 'HTTP_CLIENT_IP' );
} else {
$realip = getenv( 'REMOTE_ADDR' );
}
}
$host = @gethostbyaddr($realip);
$today = date("F j, Y, g:i a");
$sendmessage = "--------------------\n";
$sendmessage.= " - Full name: $contactformvar3\n";
$sendmessage.= " - email: $contactformvar4\n";
$sendmessage.= " - comments:\n$contactformvar5\n";
$sendmessage.= "--------------------\n";
$sendmessage.= "\n\nIP: $realip\n";
$sendmessage.= "HOST: $host\n\n";
$sendmessage.= "Date and time sent: $today";

@mail("[email protected]", "trying", $sendmessage, "From: $contactformvar3 <$contactformvar4>\r\nReply-To: $contactformvar4\r\nX-Sender: Strong CONTACT (http://www.stronghtml.com)\r\nReturn-Path: <$contactformvar4>");
print '
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td align="center" class="contactformThankYou">
thank you
</td></tr></table>';
}
}

?>[/code]

thanks

(edited by kenrbnsn to add [nobbc][code][/code][/nobbc] tags)
Link to comment
https://forums.phpfreaks.com/topic/31845-php-form-problem/
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.