Jump to content

Recommended Posts

Please pardon the noobiness; hopefully someone will find this easy to solve.  I have an email feedback form that I'd like to have do two things:

 

1. Collect a few pieces of information & mail them to the owner of the site

 

2. Send a confirmation email to the user at the email address they provide.

 

Simple, right?  There are two problems I haven't solved:

 

1. I still need an email validator.  I can check to see if something's in that field, but not whether it conforms to standard email address syntax.

 

2. The confirmation email is going out just fine, but it's basically a zombie.  It's the same email regardless of what message/inputs the user puts in the form fields.  I still need that information to be captured and sent to the owner of the site. 

 

I'm using Larry Ullman's PHP and MYSQL for dynamic websites Visual QuickPro guide as the model code, and I'm a little ticked at Larry that the email function is documented in such a cursory way.  ::shakes fist::

 

If anyone can help solve the above problems, I would be greatly appreciative.  The code I'm using is below.

___________________________________________________

 

<?php # Script 3.15 - register.php

 

if (isset($_POST['submit'])) { // Handle the form.

 

$message = NULL; // Create an empty new variable.

 

// Check for a name.

if (strlen($_POST['name']) > 0) {

$name = TRUE;

} else {

$name = FALSE;

$message .= '<p>Please enter your name.</p>';

}

 

// Check for an email address.

if (strlen($_POST['email']) > 0) {

$email = TRUE;

} else {

$email = FALSE;

$message .= '<p>Please let us know where it\'s best to email you.</p>';

}

 

// Check for message text.

if (strlen($_POST['text']) > 0) {

$text = TRUE;

} else {

$text = FALSE;

$message .= '<p>Please enter a message.</p>';

}

 

 

if ($name && $email && $text) { // If everything's okay.

// Register the user.

 

// Send confirmation to customer.

$body = "Thanks for your message.  We look forward to reading it.  \n\nSincerely,\nJoe Palooka, Acme Widget, Inc.";

mail ($_POST['email'], 'Thank you for your message!', $body, 'From: customerservice@client.com');

 

// Send an email with customer message.

$storemail .= 'testrecipient@client.com';//destination email

mail ($storemail, $name, $text,'From: customerservice@client.com');

header ('Location: thankyou.php');

exit();

} else {

$foo .= '<p>Please try again.</p>'; //I just sent this off into oblivion by calling it $foo, 'cause I don't know what else to do with it.

}

 

}

?>

 

Thanks again for having a look.

 

-Alexis

i made a change to how you're checking the fields for value and added the email regex

 

<?php
   if (trim($_POST['email']) !== '') {
      $email = TRUE;
  if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) $email = false;
   } else {
      $email = FALSE;
      $message .= '<p>Please let us know where it\'s best to email you.</p>';
   }
?>

 

i canged strlen to trim because a person could put a bunch of spaces in the field and it still passes the strlen check

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.