Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

php mail call + contact form Please Help!

Featured Replies

Hey guys.

 

I've been having some frustrating issues with my php + contact form recently. I'm quite the noob when it comes to php in general and have only really worked with contact stuff in the past.

 

I have my contact form calling a php send mail file in a php folder on my server. No idea why, but im not even getting validation. I click send, to no avail.

 

I have attached the code for your perusal. I appreciate any help in advance!! Thank you.

 

Form:

 

<form id="contact-form" class="fixed" action="javascript:void(0);">
	  <fieldset>
	   <p id="formstatus"></p>
	   <p>
		    <label for="name">Your name: <span class="required">*</span></label><br />
		    <input class="text" type="text" id="name" name="name" value="" />
	   </p>
	   <p>
		    <label for="email">Your Email Address: <span class="required">*</span></label><br />
		    <input class="text" type="text" id="email" name="email" value="" />
	   </p>
	   <p>
		    <label for="subject">Subject: <span class="required">*</span></label><br />
		    <input class="text" type="text" id="subject" name="subject" value=""  />
	   </p>
	   <p>
		    <label for="message">Message: </label><br />
		    <textarea id="message" name="message" rows="3" cols="25"></textarea>
	   </p>
	   <p>
		    <input type="submit" name="submit" value="Send!" />
	   </p>
	  </fieldset>
	 </form>

 

PHP file (send.php):

I've hidden the send to email address for obvious reasons.

 

<?php[/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]/////////// Add your own email below //////////////// [/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]define("WEBMASTER_EMAIL", 'blah@blah.com');[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]error_reporting (E_ALL ^ E_NOTICE);[/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]//////////////////////////////////////////////////////[/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]function ValidateEmail($email)
{
 $regex = '/([a-z0-9_.-]+)'. # name
 '@'. # at
 '([a-z0-9.-]+){2,255}'. # domain & possibly subdomains
 '.'. # period
 '([a-z]+){2,10}/i'; # domain extension

 if($email == '')
  return false;
 else
  $eregi = preg_replace($regex, '', $email);
 return empty($eregi) ? true : false;
}[/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]//////////////////////////////////////////////////////[/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]$post = (!empty($_POST)) ? true : false;[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]if($post)
{
 $name   = stripslashes($_POST['name']);
 $email   = trim($_POST['email']);
 $subject = trim($_POST['subject']);
 $message = stripslashes($_POST['message']);[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]  $error = '';[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]  // Check name
 if(!$name)
  $error .= 'Name required! ';[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]  // Check email
 if(!$email)
  $error .= 'E-mail required! ';[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]  if($email && !ValidateEmail($email))
  $error .= 'E-mail address is not valid! ';[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]  // Check message
 if(!$message)
  $error .= "Please enter your message!";[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]  if(!$error)
 {
  $mail = mail(WEBMASTER_EMAIL, $subject, $message,
	 "From: ".$name." <".$email.">\r\n"
    ."Reply-To: ".$email."\r\n"
    ."X-Mailer: PHP/" . phpversion());

  if($mail)
    echo 'OK';
 }
 else
  echo '<div class="errormsg">'.$error.'</div>';
}[/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]?>

 

and javascript:

 

// -------------------------------------------------------------------------------------------------------

// Form Validation script - used by the Contact Form script

// -------------------------------------------------------------------------------------------------------

 

function validateMyAjaxInputs() {

 

 

$.validity.start();

// Validator methods go here:

$("#name").require();

$("#email").require().match("email");

$("#subject").require();

 

 

// End the validation session:

var result = $.validity.end();

return result.valid;

}

 

// -------------------------------------------------------------------------------------------------------

// ClearForm

// -------------------------------------------------------------------------------------------------------

 

$.fn.clearForm = function() {

return this.each(function() {

var type = this.type, tag = this.tagName.toLowerCase();

if (tag == 'form')

return $(':input',this).clearForm();

if (type == 'text' || type == 'password' || tag == 'textarea')

this.value = '';

else if (type == 'checkbox' || type == 'radio')

this.checked = false;

else if (tag == 'select')

this.selectedIndex = -1;

});

};

 

 

$(document).ready(function(){

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

I think that on your html form you dont have a method i think its called.

 

Like you need to say POST or GET.

 

 

On your php form i didnt go thru it all in detail.

 

 

but i did see

 

 

if($email == '')

return false;

else

$eregi = preg_replace($regex, '', $email);

return empty($eregi) ? true : false;

 

 

I noticed that your else wasn't wrapped in {}

 

 

like i thought you had to write those statements like this.

 

 

if ( $t < 1) { echo "blah blah blah"; } else { "No its asscheeks didnt work im afraid" ; } //close else.

 

 

 

 

 

I dont know. To me it looks like you have an awful lot of errors in your script. But maybe there is another way of writing php that i dont know about.

 

I only write php the way i do it, I dont know everything about it.

Edited by Ernie_flowers

Also I wouldnt do this

 

 

if($email == '')

return false;

 

 

I would use

 

if (! empty($email)) {

 

 

etc etc etc } else {

 

etc etc etc }

 

I know you can run into problems writing it like $email =''.

 

I cant remeber what they were tho. I think its either because of the space having a value of space. Or empty entries on the database.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.