I am new to php. I am trying to get this below code to work. I got this from some other forum. Now the issue is I don't get any email after i hit send. It is not showing any error message or anything. I think the form is working, but i am not getting the email. I try to test this using my personal email ID. Can anyone help me to fix the issue?
thanks in advance
Peach
Code: Select all
<?php
# home page for link at top of page:
$home = "http://www.xxxx.com/xx.html";
# Modify the following variables to set up where emails will be sent.
# $toName will be concatenated with a "@" and then $toDomain to create
# the complete email address.
$toName = "microsoft_sucks0"; # the part that goes before the @
$toDomain = "yahoo.com"; # the part that comes after the @
# To cc someone:
$ccName = "ccname";
$ccDomain = "ccdomain.com";
# To bcc someone:
$bccName = "bccname";
$bccDomain = "bccdomain.com";
#################################
# end of user-defined variables
##################################
# email address validation function
function is_valid_email_address($email) {
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$quoted_pair = '\\x5c\\x00-\\x7f';
$domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
$quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\\x2e$sub_domain)*";
$local_part = "$word(\\x2e$word)*";
$addr_spec = "$local_part\\x40$domain";
return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
}
# Init. some variables:
$error = "";
$success = FALSE;
# process form if submitted:
if(isset($_POST['submit'])){
foreach($_POST as $key => $val) {
if (empty($_POST[$key])) {
$error .= "You must enter a value for " .
ucwords(str_replace("_"," ",$key)) . ". ";
}
else {
if(get_magic_quotes_gpc()) {
$_POST[$key] = stripslashes($val);
}
}
if($key != 'message') {
$_POST[$key] = preg_replace('/[\r\n]/', ' ', $val);
}
}
if($_POST['email_address'] != $_POST['repeat_email']) {
$error .= "Email Address is not the same as Repeat Email. ";
}
elseif(is_valid_email_address($_POST['email_address']) == 0) {
$error .= "'{$_POST['email_address']}' does not appear to be a valid email address. ";
}
if(empty($error)) # no errors in input, so go ahead and email it.
{
$to = "$toName@$toDomain";
$headers = "From: ".preg_replace('/[\r\n]+/',' ', $_POST['email_address']);
if(!empty($ccName) and !empty($ccDomain)) {
$headers .= "\r\nCc: $ccName@$ccDomain";
}
if(!empty($bccName) and !empty($bccDomain)) {
$headers .= "\r\nBcc: $bccName@$bccDomain\r\n\r\n";
}
$headers .= "\r\nX-Mailer: PHP/" . phpversion();
$msg = "From {$_POST['name']} ({$_POST['email_address']})";
$msg .= "\n\n\n{$_POST['message']}";
echo "<pre>$headers"; exit;
$result = @mail($to,
stripslashes($_POST['subject']),
$msg,
$headers);
if(!$result) {
$error = "There was an unknown error while attempting to send your email.";
}
else {
header("Location: http://www.charles-reace.com/Email_Me/thanks.php");
}
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
<title>Email Me</title>
<style type="text/css">
body { width: 950; background: #E7EFD6 ; color:#002200; margin: 0px 150px 0 37px;
font-family:verdana,arial,sans serif; font-size:12px;}
.lab {margin-left:3px;display: block; float: left; width: 9em;}
legend {font-size:13px;font-weight:bold;}
.img-header {clear: both; float: left; width: 950px; height: 90px; margin: 0px; padding: 0px;}
</style>
</head>
<body>
<?php
if(!empty($error)){
echo "<p style='color: #c03;'>$error</p>\n";
}
?>
<h2>Email Me</h2>
<form action='<?php echo $_SERVER['PHP_SELF'] ?>' method=post>
<fieldset>
<legend>Your Contact Information</legend>
<p><label for='name' class='lab'>Name:</label>
<input type='text' name='name' id='name' size='30' maxlength='40'<?php
if(!empty($_POST['name'])){
echo "value='{$_POST['name']}'";
}
?>></p>
<p><label for='email_address' class='lab'>Email Address:</label>
<input type='text' name='email_address' id='email_address' size='30' maxlength='40'<?php
if(!empty($_POST['email_address'])){
echo "value='{$_POST['email_address']}'";
}
?>></p>
<p><label for='repeat_email' class='lab'>Repeat Email:</label>
<input type='text' name='repeat_email' id='repeat_email' size='30' maxlength='40'<?php
if(!empty($_POST['repeat_email'])) {
echo "value='{$_POST['repeat_email']}'";
}
?>></p>
</fieldset>
<p> </p>
<fieldset>
<legend>Message</legend>
<p><label for='subject' style="margin-left:3px;display: block; float: left; width: 9em;">Subject:</label>
<input type='text' name='subject' id='subject' size='50' maxlength='60'<?php
if(!empty($_POST['subject'])){
echo " value='{$_POST['subject']}'";
}
?>></p>
<p><label for='message' style="margin-left:3px;display: block; float: left; width: 9em;">Message:</label>
<textarea name='message' id='message' cols='50' rows='8'
style="width: 375px"><?php
if(!empty($_POST['message'])){
echo $_POST['message'];
}
?></textarea></p>
<p style="text-align: center;"><input type='submit' name='submit' value="Send Email"></p>
</fieldset>
</form>
</body>
</html>