1

I am coding a personal website and having an issue with my contact from. If you can help me find what's wrong I would really appreciate it.

The link to the website is www.tiryakicreative.com and the code for the php form is given below:

<div id="form">
<form id="ajax-contact-form" action="contact_form/send_form_email.php…
<fieldset class="info_fieldset">
<div id="note"></div>
<div id="fields">
<label>Name</label>
<input class="textbox" type="text" name="name" value="" />
<label>E-Mail</label><input class="textbox" type="text" name="email" value="" />     
<label>Subject</label>
<input class="textbox" type="text" name="subject" value="" />
<label>Message</label>
<textarea class="textbox2" name="message" rows="5" cols="25"></textarea>
<label> </label><input class="button" type="image" src="send2.gif" id="submit"   Value="Send Message" />    
</div>
</fieldset>
</form>
</div>
</div>

Here is the php code for the given html code:

<?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "New Email from Website";


function died($error) {
// ERROR CODE GOES HERE
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.";
echo $error."";
echo "Please go back and fix these errors.";
die();
}

// validation expected data exists
if(!isset($_POST['name']) || 
!isset($_POST['email']) ||
!isset($_POST['subject']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.'); 
}

$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['subject']; // not required
$comments = $_POST['message']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Z…
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The Name you entered does not appear to be valid.';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The subject you entered does not appear to be valid.';
}
if(strlen($comments) < 2) {
$error_message .= 'The message you entered do not appear to be valid.';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:",…
return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Subject: ".clean_string($telephone)."\n";
$email_message .= "Message: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>

<!-- include success html here -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
?>
6
  • What happens when you try to send an email? Oct 27, 2012 at 22:34
  • blank page opens and no action...
    – Tiryaki
    Oct 27, 2012 at 22:34
  • 1
    When PHP gives you a blank page, you should check the web server log files. Also, I assume the ellipses ("…") are not present in the actual code. Oct 27, 2012 at 22:39
  • I double checked the code for ellipses and no, they are not present.
    – Tiryaki
    Oct 27, 2012 at 22:46
  • It's kind of strange syntax to have a function in the middle of that code segment. You should def check the server log for error messages.
    – ethrbunny
    Oct 27, 2012 at 23:29

3 Answers 3

0

Are you receiving the emails after the user sends the email?

1
  • That is a comment, not an answer.
    – Arjan
    Oct 28, 2012 at 9:34
0

Try adding

error_reporting(E_ALL);

to the top of your script.

You could also try removing the @ from the mail command

mail($email_to, $email_subject, $email_message, $headers); 

As this will be suppressing any errors that is being generated.

It could be something as simple as the PHP mail function having additional headers disabled (some hosts do this for security reasons) in which case the mail function will fail.

0

set this is in your action form ... and you will definately get mail from here.. and although there is an error you may be use use below code for send mail using php without declare a variable... like

$email_to=$_POST['email'];
$email_subject=$_POST['subject'];
$email_message=$_POST['message'];
$headers=$_POST['title'];

    mail('$email_to', '$email_subject', '$email_message', '$headers');

otherwise use below code for send mail

mail('$_POST['email']','$_POST['subject']','$_POST['message']','$_POST['title']');
1
  • Simply using the POST array directly is both a security risk and is no guarantee you will "definitely get a mail from here" as there may be other reasons the mail function is failing.
    – foamcow
    Oct 28, 2012 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.