Jump to content

Contact Form From Hell – Help Needed


ceilingwalker

Recommended Posts

I’ve been attempting to get an AJAX contact form to work, but I’m out of ideas and need the help of a guru. The code was created by a third-party, but I’m starting to think it’s not even valid. I’ve pasted all of the code below for your review, from HTML, to JS, to the PHP. Any suggestions on how to make my contact form work would be greatly appreciated.

 

HTML CODE:

 

<div class="contact_submit_form form_24" style="width:600px;">

<div class="quickly_elements_left">

<div class="quickly_elements_label">
<input type="text" name="name" class="input" value="Name *">
</div>

<div class="quickly_elements_label">
<input type="text" name="email" class="input" value="Email *">
</div>

<div class="quickly_elements_label">
<input type="text" name="telephone" class="input" value="Telephone">
</div>

</div>

<div class="quickly_elements_right">
<div class="quickly_elements_label">
<input type="text" name="subject" class="input" value="Subject *">
</div>
<div class="quickly_elements_label">
<textarea class="textarea" name="message" style="width:90%; height:65px;">Message *</textarea>
</div>
</div>

<div class="quickly_elements_label">
<div class="form_24 contact_submit alignright"><h6><span class="small_buttons"><span class="ocean_l small_left"><span class="ocean_r small_right">Send Message</span></span></span></h6></div>
<div class="quickly_form_message alignright"> </div>
</div>

</div>

 

JS

 


/* contact form and comment for settings */
_form_name 				= "Name *"; 
_form_email				= "Email *"; 
_form_tel				= "Telephone"; 
_form_subject			= "Subject *"; 
_form_message			= "Message *"; 
_form_comment			= "Message *"; 
_form_url				= "Web Site";  
_error_name				= "Error, Please check <strong>your name</strong> "; 
_error_email			= "Error, Please check <strong>your email</strong> "; 
_error_subject			= "Error, Please check <strong>your subject</strong> "; 
_error_message			= "Error, Please check <strong>your message</strong> "; 
_error_comment			= "Error, Please check <strong>your comment</strong> "; 
_send_message			= "Please wait, sending..."; 
_thanks_message			= "Success! Thank you for contact.";   

 

PHP

 

<?php
/*
Getting & Settings some variables
*/
$address 		= "emailaddess@test.com"; /* Change here, write your email adress */

/* 
If mail messages are not received, try using a LF (\n) only. 
Some poor quality Unix mail transfer agents replace LF (\n) by CRLF (\r\n) 
automatically (which leads to doubling C (\r) if CRLF (\r\n) is used).. 
also you can change field names from Translate Settings 
*/
$email_set		= "LF";

$name			= $_REQUEST["name"];
$email			= $_REQUEST["email"];
$tel			= $_REQUEST["tel"];
$subject		= $_REQUEST["subject"];
$content		= $_REQUEST["message"];

$sender			= mb_encode_mimeheader($name, "UTF-7", "Q") . " <" . $email . ">";
$subject_utf	= mb_encode_mimeheader($subject,"UTF-8", "B", "\n");


function Sendmail($from, $to, $subject, $plain, $html = false, $charset = "iso-8859-1") {


if($email_set == "CRLF"){
	$lb = "\r\n";
}else if($email_set == "LF"){
	$lb = "\n";
}

if($html == false) {

	$headers = "From: ".$from.$lb;
	$headers .= "Reply-To: ".$from.$lb;
	$headers .= "MIME-Version: 1.0".$lb;
	$headers .= "X-Priority: 3".$lb;
	$headers .= "X-Mailer: RobustMail [1.0]".$lb;
	$headers .= "Content-type: text/html; charset=".$charset.$lb;
	$mail_sent = @mail($to, $subject, $plain, $headers);
	return $mail_sent;

}

$random_hash = md5(microtime());
$headers = "From: ".$from.$lb;
$headers .= "Reply-To: ".$from.$lb;
$headers .= "MIME-Version: 1.0".$lb;
$headers .= "X-Priority: 3".$lb;
$headers .= "X-Mailer: RobustMail [1.0]".$lb;
$headers .= "Content-Type: multipart/alternative;".$lb."\tboundary=\"bo_".$random_hash."\"";

ob_start();

?>
--bo_<?php echo $random_hash.$lb; ?>
Content-Type: text/plain; charset = "<?php echo $charset; ?>"
Content-Transfer-Encoding: 7bit

<?php echo $plain; ?>


--bo_<?php echo $random_hash.$lb; ?>
Content-Type: text/html; charset = "<?php echo $charset; ?>"
Content-Transfer-Encoding: 7bit

<?php echo $html; ?>




--bo_<?php echo $random_hash; ?>--
<?php
$message = ob_get_clean();
$to = is_array($to) ? implode(", " , $to) : $to;
$mail_sent = @mail($to, $subject, $message, $headers);
return $mail_sent;
}

$mailBody	 = "";
$mailBody	.= "You got an email from your website!<br /><br />";
$mailBody	.= "Name : ". $name . "<br />";
$mailBody	.= "Email : ". $email . "<br />"; 
$mailBody	.= "Telephone : ". $tel . "<br />"; 
$mailBody	.= "Subject : ". $subject . "<br />";
$mailBody	.= "Message : ". $content . "<br />";

$send_mail = sendMail($sender, $address, $subject_utf, $mailBody, $html = false, $charset = "utf-8");

$thanks_message	= "Success! Thank you for contact.";
$error_message	= "Mail Failed, Please try again!";

if( $send_mail ) { echo $thanks_message; } else { echo $error_message; }

?>

Link to comment
Share on other sites

In order for people to help you, you need to tell us what is wrong. "Does not work" is not a a description of a problem. Tell us what it should do, and what it does do. That being said, I quickly scanned through the code and the following things jump out at me:

 

[*]The form fields names are using "proper case" (i.e. Subject) but the PHP is looking for them using lower case (i.e. subject);

[*]Remove the "@" symbol in the two calls to mail (it should NOT be @mail(...), it should be mail(...)) - the "@" hides any errors that occur, errors should be fixed not hidden;

[*]Turn on error reporting in development so you can see the errors and fix them

[*]There is no <FORM> tag in there;

[*]There is no AJAX or even any JavaScript code to call AJAX in there

 

For error reporting, put this at the top of the PHP file:

 



<?php
error_reporting(E_ALL);
ini_set("display_errors",1);

 

Link to comment
Share on other sites

What should be happening is that when someone submits a completed contact form there should be a confirmation stating that it was processed correctly and then I should receive an email with the submitted information. The confirmation appears to work, but the email is never received. You can see it in action on a temporary website here  www.notallgood.com.

 

It sounds like from your quick assessment that the contact form in its current state is not functional, but rather impersonating a contact form. Would you recommend me using different code or do you think what I have is salvageable?

 

Thank you,

Ryan

 

Link to comment
Share on other sites

I really don't know how to answer that question. It would depend on what you are comfortable with and what your level of expertise is.

 

In your original post, you stated:

I’ve pasted all of the code below

But there is no <FORM> tag in the code. I do not see any way that the form is submitting to your PHP code without a FORM tag. So, I don't know if that is all of the code, or most of the code, or what. And, I really cannot say whether the code is salvageable or not.

 

If your code is executing and saying it sent the email, and you do not receive the email, there are a few things to look at there:

 

1) the mail function simply submits the mail to the (local) mail server. If it hands it off OK the function returns true. So, you need to make sure you have a working mail system installed.

 

2) The email address supplied in the FROM header really needs to be an email address that belongs to the server sending the mail. Otherwise, the server sending the mail may think you are trying to send a forged email and refuse to SEND it. Also, the server receiving the mail may believe it is forged and refuse to deliver it. (or it might be in your junk mail folder).

 

 

Link to comment
Share on other sites

You are correct. There is no <form> tag so I think it’s the Java that is stating the form is submitting, but it never actually ever talks to the PHP. I think I might not have been given the best code.

 

Do you recommend any easy to integrate contact form code that I could use? My goal is to have the code submit without needing to need to load a new page, but still have a confirmation that it went through.

 

Thank you,

Ryan

 

Link to comment
Share on other sites

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.