Hello there all …
I need someone who knows php to take a look at the following code to see if you can find an error.
- What is happening is I cannot get the email to send
- There is no success or error message displayed when submited
I do not know php and I cannot contact the developer of the script as they are not answering. Ths is the orginal script and the email address is not changed. In the form I am using the email is changed.
[PHP]
<?php /* --------------------------------------------------- SonicFog Web Development ------------------------------------------- a division of SeniorGlobe Media Inc ------------------------------------------- This code is Copyright Protected SeniorGlobe Media Inc. 2005 --------------------------------------------------- */ //This script is easy to use. Just include this page in any of your php pages and it will proccess a custom form. //You can add as many input fields as you like to customize your form, they will all be processed. //Settings to edit $MailSubject = "Customer Contact"; // edit the subject of the email $CompanyName = "My Company"; //edit - this could be a division like Support Team, this shows on the confirmation page //change these to make your subject dropdown and handle mail routing, add as many as you like $SubjectArray = array( "Pre-sales" => "[email protected]", "Business Proposition" => "[email protected]", "Request Consultation" => "[email protected]", "Other" => "[email protected]" ); //enter blocked ip addresses below separated by commas $BlockedIP = "1.1.1.1"; //enter blocked email addresses below between the quotes $BlockedEmail = "[email protected], [email protected]"; //Sonic Version $sonic_ver = "1.0.1"; //1.0.1 added security and routing function valid_email($email) { // Check for a valid email address. $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,6})$"; // Get the hostname. $fromHost = explode("@", $_POST['email']); // Test for both valid syntax and a valid server. if ( !eregi($regexp, $_POST['email']) || !checkdnsrr($fromHost[1], "MX") ) { return false; }else{ return true; } } if($_POST["step"] == "send"){ $send_email = "yes"; //lets try to make it no //no name, you can't contact us without a name if(!$_POST["name"]){ $send_email = "no"; $error_message_name = "Please enter your name below."; } //contact pref is phone but no phone number entered if($_POST["contact_preference"] == "phone" && !$_POST["phone"]){ $send_email = "no"; $error_message_phone = "You chose phone as your contact preference, but you did not enter your phone number. Please enter it now."; } if($_POST["rc"] != $_POST["rc2"]){ $send_email = "no"; $error_message_security = "Your security characters did not match ours. Please try again.IP Address Logged As: $REMOTE_ADDR"; } //check for valid email format if (!valid_email($email)){ $send_email = "no"; $error_message_email = "Your email address appears invalid. Please re-enter it below."; } //check for blocked ips $sonicx = strstr($BlockedIP, getenv('REMOTE_ADDR')); if($sonicx == TRUE){ $send_email = "no"; $error_message .= "Sorry but we could not process your form at this time."; $error_type = "fatal"; } $sonicxemail = @strstr($BlockedEmail, $_POST["email"]); //echo "Post email =". $_POST["email"]; //echo "sonicxemail =". $sonicxemail; if($sonicxemail == TRUE){ $send_email = "no"; $error_message .= "Sorry but we could not process your form at this time."; $error_type = "fatal"; } if (preg_match ("/".str_replace("www.", "", $_SERVER["SERVER_NAME"])."/i", $_SERVER["HTTP_REFERER"]) && ($send_email == "yes")){ //start formatting and building the message // handle post strings reset($_POST); while(list($key, $val) = each($_POST)) { $GLOBALS[$key] = $val; if (is_array($val)) { $sonicMessage .= "$key: "; foreach ($val as $vala) { $vala =stripslashes($vala); $vala = htmlspecialchars($vala); $sonicMessage .= "$vala, "; } $sonicMessage .= "
\n"; }else{ $val = stripslashes($val); if (($key == "Submit") || ($key == "submit")){ }else{ if ($val == ""){ $sonicMessage .= "$key: -
\n"; }else{ $sonicMessage .= "$key: $val
\n"; } } } } // end while //determine the mail routing foreach($SubjectArray as $key=>$val){ if($_POST["subject"] == $key){ $MailToAddress = $val; } //end if } //end foreach $sonicMessage .= "
\n Sender IP: ".getenv('REMOTE_ADDR').""; $sonic_what = array("/To:/i", "/Cc:/i", "/Bcc:/i","/Content-Type:/i","/\n/"); $name = preg_replace($sonic_what, "", $name); $email = preg_replace($sonic_what, "", $email); $sonicMessage = preg_replace($sonic_what, "", $sonicMessage); if (!$email) { $email = $MailToAddress; } // end if no email $mailHeader = "From: $name <$email>\r\n"; $mailHeader .= "Reply-To: $name <$email>\r\n"; $mailHeader .= "Message-ID: <". md5(rand()."".time()) ."@". ereg_replace("www.","",$_SERVER["SERVER_NAME"]) .">\r\n"; $mailHeader .= "MIME-Version: 1.0\r\n"; $mailHeader .= "Content-Type: multipart/alternative;"; $mailHeader .= " boundary=\"----=_NextPart_000_000E_01C5256B.0AEFE730\"\r\n"; $mailHeader .= "X-Priority: 3\r\n"; $mailHeader .= "X-Mailer: PHP/" . phpversion()."\r\n"; $mailHeader .= "X-MimeOLE: Produced By SonicFog Contact Form Ver $sonic_ver\r\n"; $mailMessage = "This is a multi-part message in MIME format.\r\n\r\n"; $mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730\r\n"; $mailMessage .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"; $mailMessage .= strip_tags($sonicMessage)."\r\n\r\n"; $mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730\r\n"; $mailMessage .= "Content-Type: text/html; charset=\"ISO-8859-1\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n"; $mailMessage .= "$sonicMessage\r\n\r\n"; $mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730--\r\n"; if(!mail($MailToAddress, $MailSubject, $mailMessage,$mailHeader)){ //everything worked but the mail function echo "Error sending e-mail! Please try again later."; }else{ //success message ?>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<br><span class='text'>Dear <? echo $name; ?>
<br>We have received your message below and will take appropriate action as soon as possilbe.
<br>Thank you,
<br><? echo $CompanyName; ?>
<br><br>Your Message:<br><font color=blue><? echo $message; ?>
</font>
</span>
</td>
</tr>
</table>
<?
}
}
} //end if step == send
if($_POST[“step”] != “send” || $send_email == “no”){
if($error_type == “fatal”){
echo “”.$error_message.“”;
}else{
?>
<?
if($error_message_name){
?>
<?
}
?>
<?
if($error_message_email){
?>
<?
}
?>
<?
//add additional rows with additional input fields here, they will be processed by the script
?>
<?
if($error_message_phone){
?>
<?
}
?>
<?
//generate random numbers
$random_characters = substr(md5(sha1(date("U"))), 0, 5);
$rc1 = substr($random_characters, 0, 1);
$rc2 = substr($random_characters, 1, 1);
$rc3 = substr($random_characters, 2, 1);
$rc4 = substr($random_characters, 3, 1);
$rc5 = substr($random_characters, 4, 1);
} //end if step != send | ||||||||||||||||||