Php Programming Code Examples
Php > E-Mail Code Examples
Sample WML Mailer
Sample WML Mailer
<?php
header("Content-type: text/vnd.wap.wml");
echo "<?xml version=\"1.0\" ?>\n";
$recipient_mail = "[email protected]";
$recipient_name = "Webmaster";
$sender_name = "WapMail";
$sender_mail = "[email protected]";
$subject = "News Letter Subscription";
$message = "News Letter Subscription\n\n";
function CheckEmail ($email) {
$error = FALSE;
# -- note first blank is a placeholder
$punctuation = " ~!#$%^&*()+|{}[]:;?<>,/?\\\'\"";
$strpos = strpos($email,"@");
if (!$strpos) {
$error = TRUE;
} elseif (strpos($email,"@",$strpos +1)){
$error = TRUE;
} else {
for ($i = 0; $i < strlen($punctuation); ++$i) {
$error = strpos($email,$punctuation[$i]);
if ($error > 0) {
$test = isset($error);
$error = TRUE;
break;
}
}
}
if (!$error) {
list($user,$domain)= split("@",$email,2);
$arr = explode(".",$domain);
$count = count($arr);
if (strlen($user) < 1) {
$error = TRUE;
} elseif ($count < 2) {
$error = TRUE;
} elseif (strlen($arr[$count-1]) < 2) {
$error = TRUE;
} elseif (strlen($arr[$count-2]) < 2) {
$error = TRUE;
}
}
return ($error);
}
?>
<wml>
<head>
<meta http-equiv="Cache-Control" content="max-age=0" forua="true"/>
</head>
<!-- add a template here if you have one -->
<card id="subscribe1" title="yourdomain.com">
<p>
<b>Newsletter Subscription</b><br/>
<small>
<?PHP if (!$mode): ?>
Please ener information below<br/>
First Name<br/>
<input name="fname" value=""/><br/>
Last Name<br/>
<input name="lname" value=""/><br/>
E-mail Address<br/>
<input name="email" value=""/><br/>
<anchor title="Submit">[Submit]
<go href="http://yourdomain.com/wap/subscribe1.php" method="post">
<postfield name="fname" value="$(fname)"/>
<postfield name="lname" value="$(lname)"/>
<postfield name="email" value="$(email)"/>
<postfield name="mode" value="1"/>
</go></anchor> ?
<a href="http://yourdomain.com/wap/">[Home]</a>
<?php elseif ($mode): ?>
<?php
$error = FALSE;
$errtxt = "";
if (empty($fname)) {
$error = True;
echo "First Name is blank<br/>";
}
if (empty($lname)) {
$error = True;
echo "Last Name is blank<br/>";
}
if (empty($email)) {
$error = True;
echo "E-mail is blank<br/>";
} elseif (CheckEmail($email) ) {
$error = True;
echo "Invalid E-mail address<br/>";
}
# If passed edit display thanks and send mail
If (!$error) {
echo "Thanks your subscription has been entered.";
$message .= "First Name : " . $fname . "\n";
$message .= "Last Name : " . $lname . "\n";
$message .= "E-Mail : " . $email . "\n";
$message .= "Entered : " . date("m/d/y h:i") . "\n";
mail("$recipient_name <$recipient_mail>","$subject","$message",
"From: $sender_name <$sender_mail>\nReply-To: $sender_name
<$sender_mail>\nContent-type: text/plain\nX-Mailer: PHP/" . phpversion());
} else {
echo "Press back to correct errors.<br/>";
echo "<do type='prev' label='Back'><prev/></do>";
}
?>
<?php endif; ?>
</small>
</p>
</card>
</wml>