Jump to content

Where to Place Confirmation Code


chome4

Recommended Posts

Got this working script that sends email via a form:

<?php
if(empty($_POST) === false) {
  $errors = array();

  $name = $_POST['name'];
  $email = $_POST['email'];
  $message = $_POST['message'];


  if(empty($name) === true || empty($email) === true || empty($message) === true) {
    $errors[] = 'name, email and message are required!';

  } else {
      if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
      $errors[] = 'Not valid email';
    }
    if (ctype_alpha($name) === false) {
    $errors[] = 'name contain letters!';
  }

}


if(empty($errors) === true)

{
  mail('XXXXXXX@gmail.com','contact form',$message, 'From: '.$email);
  header('Location: index.php?sent'); exit();
}

}

?>

 

Problem is, I want a bar to appear saying 'Message Sent. We Will Contact You Shortly'.

I'm brand new to php and followed a tutorial for the above. It's a simple form that I understand, apart from the code needed for confirmation!

Please can someone offer any assistance.

Thanks in advance......

 

Link to comment
Share on other sites

First - do you know that what you have so far actually works??? Your 'from' address has to be valid for the mail server to use.  You're allowing the user to provide it which is probably not what you want to have happen.

A bar?  You mean like a moving 'progress' bar?  Or just a 'line' of text?

Link to comment
Share on other sites

Regarding your edits:

	if (ctype_alpha($name) === false)
	{
    $errors[] = 'name contain letters!';
	}
	


 Do you WANT letters or not?

As a newbie how about this:

	if (!ctype_alpha($name))
	   $errors[] = 'Name must be all alphabetic';
	

And this could be different:

if(empty($errors))
{
	if (mail('XXXXXXX@gmail.com','contact form',$message, 'From: '.$email))
 	{
	   	header('Location: index.php?sent');
	   	exit();
	} 
	else
	{
		echo "Message not sent";
		exit();
	}
}
	

Note the use of separate physical lines for each line of code.  Combining them makes for troublesome reading down the road.  Trust me.

Also - the php mail function is not the greatest mail tool.  It only offers a boolean response and that can be wrong without you knowing it.

 

Edited by ginerjm
Link to comment
Share on other sites

The contact form actually works! Here's a link to the full site from which it comes:

http://test.ericfinlayartist.co.uk/

I've removed my email but just tested it and it works, no confirmation, of course.

Yes, I just want a line of text. I can format it with CSS later.

Yep, still learning, but have been asked to help a friend out who wants the site. She understands!

Link to comment
Share on other sites

In case you're not aware, you'll likely experience problems down the road (if not already) with letting people supply the "From" argument for the mail function. The server that sends the message is only going to be authorized to send email from certain domains. Sending messages from domains it's not authorized to use (e.g. gmail.com) will result in a higher chance of being sent to spam...or being dropped altogether without a warning to the sender, recipient, or your server. It just gets dropped. Whether it marked as spam or dropped is up to the server responsible for the domain being spoofed (which is what your code is doing) and/or the email provider used by the person receiving the message.

Link to comment
Share on other sites

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.