Jump to content


Photo

EmailForm


  • Please log in to reply
62 replies to this topic

#1 summean

summean

    Etomite Forum Fan

  • Member
  • Pip
  • 89 posts

Posted 13 September 2004 - 04:53 PM

I have added a new snippet to the Snippet Library!

Snippet name: EmailForm
Author: summean
Version: 0.3 (Final)
More info: View this snippet
Description:
Allows users to email you from your site!

Please feel free to comment on this snippet, suggest improvements, or simply praise my work! ;)

[This is an automatically created message]

#2 myispnet

myispnet

    Etomite Forum Newbie

  • Member
  • 16 posts

Posted 14 September 2004 - 05:15 AM

I have added a new snippet to the Snippet Library!

Snippet name: EmailForm
Author: summean
Version: 0.3 (Final)
More info: <a href="http://www.etomite.c...snipid=15">View this snippet</a>
Description:
Allows users to email you from your site!

Please feel free to comment on this snippet, suggest improvements, or simply praise my work! ;)

[This is an automatically created message]


I just added this snippet to my etomite site, www.kompukit.com and it won't work...how come? Plus, what are are those "N's" for? in the code?

#3 jaredc

jaredc

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,193 posts

Posted 14 September 2004 - 01:08 PM

I just added this snippet to my etomite site, www.kompukit.com and it won't work...how come? Plus, what are are those "N's" for? in the code?

What error are you getting? Please describe in more detail what isn't happening.

And as far as the n's go, they should be written "\n" instead of "n." This is the newline special character and will act as a carriage return in the SOURCE code- as you look at the page in the browser, it actually has no effect.

So line's like:

$SendMail .= "</select><br><br>n";
should be:

$SendMail .= "</select><br><br>\n";
And it's worth mentioning that the "\n" only works inside double quotes strings, not single quotes strings:

// this works
$string = "Some string characters.\n";
// this doesn't work
$string = 'Some string characters.\n';
I learned that lesson the hard way :D

#4 summean

summean

    Etomite Forum Fan

  • Member
  • Pip
  • 89 posts

Posted 14 September 2004 - 03:05 PM

So line's like:

$SendMail .= "</select><br><br>n";
should be:

$SendMail .= "</select><br><br>\n";

Good call Jared! B) For some reason when I copied the script from Notepad into the new snippet post, all of the \n 's became just n 's! Really weird....
Anyways, I would update it right now, but it seems the Edit Snippet feature in the Snippet Library is currently down. So for now, you'll need to add a backslash ( \ ) in front of all the ( n )'s towards the bottom of the snippet if you got it from the new snippet system.

#5 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 14 September 2004 - 03:28 PM

The problem you are describing probably ties in with a similar problem being discussed Here... Give that thread a read and I'm relatively sure that you are also experiencing that problem, as well... Although these issues are a bit of an inconvenience, they will be remedied in due time... :eto: Due to these few bugs, I am refraining from re-posting my snippets until these issues have been corrected... All of my snippets are available on my site for anyone who would like them prior to being re-posted... B)

#6 luislacerda

luislacerda

    Etomite Forum Fan

  • Member
  • Pip
  • 87 posts

Posted 14 September 2004 - 09:01 PM

I'v changed the 'n's' to '\n's' as described. The snippet is now working.
I edited the code to reflect my settings and the mails I receive in the message panel show like this one below,

Name: : :nnThis is a test message


I also do not get a From: email address in the email header. I presume it should be added to the email message after Name but nothing shows.
The subject is correctly added to the message

Can someone tell me what may be wrong?
Tkx
Luis

#7 Guest_Alex_*

Guest_Alex_*
  • Guests

Posted 14 September 2004 - 09:08 PM

Probably it's the snippet library not functioning exactly as it did on my machine at home. It'll be fixed this weekend ;)

#8 summean

summean

    Etomite Forum Fan

  • Member
  • Pip
  • 89 posts

Posted 14 September 2004 - 10:10 PM

Luislacerda (and others):

Until Alex gets the Snippet Library working, use the code in the following attachment instead. B)

Attached File  EmailForm_0.4.txt   4.17KB   254 downloads

#9 summean

summean

    Etomite Forum Fan

  • Member
  • Pip
  • 89 posts

Posted 20 September 2004 - 07:36 PM

I have updated this snippet in the Snippet Library!

[This is an automatically created message]

#10 Guest_rthrash_*

Guest_rthrash_*
  • Guests

Posted 07 October 2004 - 08:53 AM

FYI, make turn off caching for the page that you put this snippet on or you'll run into a non-working page that'll keep you scratching your head for a while. At least that's what happened to me. ;)

#11 summean

summean

    Etomite Forum Fan

  • Member
  • Pip
  • 89 posts

Posted 07 October 2004 - 03:01 PM

turn off caching for the page that you put this snippet on or you'll run into a non-working page that'll keep you scratching your head for a while.

Thanks for the info!

You can also insert the snippet into page like: [!EmailForm!] --this way it won't be cached either...

#12 Guest_rthrash_*

Guest_rthrash_*
  • Guests

Posted 07 October 2004 - 06:20 PM

You can also insert the snippet into page like: [!EmailForm!] --this way it won't be cached either...

Does that do partial page caching?

#13 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 07 October 2004 - 06:28 PM

Does that do partial page caching?

You could call using [! ... !] partial caching due to the fact that this method only effects that particular snippet, and not the overall page rendering... :eto: Actually, any page which displays dynamic content should not utilize page caching and using this method to call a snippet will override any setting of a documents Cacheable flag for the any data returned by the snippet called... B)

#14 Guest_rthrash_*

Guest_rthrash_*
  • Guests

Posted 12 October 2004 - 10:45 PM

I've made some minor revisions to the snippet so that the resulting page will validate as XHTML for those interested. Thanks for making this one in the first place :)

// --------- Email Form (Etomite 0.6) ------------
// Version 0.6.4 - September 12, 2004 - Tony Summerville
// CSS classes used:
// emailform - used in the actual form.
// emailformMessage - messages to the user.
// error -- used when there is a problem with some part of the validation
// message -- general feedback that is not an error... e.g. the message was sent
// Config is down a bit....
///////////////////////////////////
// DO NOT MESS WITH THESE TWO LINES
$subject_array = array();
$recipient_array = array();
///////////////////////////////////
//  <-----  BEGIN CONFIG  ----->
// Edit only what's between the quotation marks in the below lines.
// These will be the subjects that your users can choose from
// You can have as many as you want.
// Each one must be set up like so:
// $subject_array[] = "What You Want This Choice To Be";
// Make sure to remove empty ones that you aren't using. Just delete the entire line.

$subject_array[] = "Subject Choice 1";
$subject_array[] = "Subject Choice 2";
$subject_array[] = "Subject Choice 3";
//$subject_array[] = "Subject Choice 4";
// Insert as many as you'd like

// Edit only what's between the quotation marks in the below lines.
// These lines contain the various people that can be contacted via your form.
// You can have as many as you want.
// Each one must be set up like so:
// $recipient_array["UNIQUE Short Name"] = "email@email.com";
// The "UNIQUE Short Name" will be shown in the select box.
// This allows the actual email address to be hidden from the user.
// Make sure to remove empty ones that you aren't using. Just delete the entire line.

$recipient_array["General Inquiry"] = "\"my-email@mydomain.com\"";
// $recipient_array["Recipient 2"] = "\"test2@test.com\"";
// again, insert as many as you'd like

//  <-----  END CONFIG  ----->


if ($_POST['send'] == 'true') {
    $to = $_POST['to'];
    $name = $_POST['name'];
    $email = $_POST['email'];
    $the_subject = $_POST['subject'];
    $message = $_POST['message'];
    if (($name == '') OR ($email == '') OR ($message == '')) {
$SendMail .= "<div class='error'>";
$SendMail .= "One of the fields was left blank. Please put something in all fields.";
$SendMail .= "</div>";
	}
        elseif (ereg('([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)', $email)) {
	$recipient = $to;
	$subject = $the_subject;
	$additional_headers = "From: $email\n";
	$body = "Name: $name\nEmail: $email\n\nMessage:\n\n" . $message;
	if (mail($recipient, $subject, $body, $additional_headers)) {
$SendMail .= "<div class='message'>";
$SendMail .= "Message sent successfully!  Someone will contact you soon.";
$SendMail .= "</div>";
	$name="";
	$email="";
	$message="";
	} else {
$SendMail .= "<div class='error'>";
$SendMail .= "Error! Please try again.<br>";
$SendMail .= "</div>";
     $send = "false";
	}
	} else {
$SendMail .= "<div class='error'>";
$SendMail .= "The email address you supplied (".$email.") does not appear to be valid. Please try again.";
$SendMail .= "</div>";
        $send = "false";
	} 
	} else {
$SendMail .= "<p>Select your inquiry type from the box below and fill out the form.</p>";
	}

$SendMail .= "<div class='emailform'>";
$SendMail .= "<form name='EmailForm' method='post' action=''>\n";
$SendMail .= "<input type='hidden' name='send' value='true' />\n";
$SendMail .= "<select name='to'>\n";
    foreach ($recipient_array as $key => $value) {
$SendMail .= "<option value=" . $value . ">" . $key . "</option>\n";
        }
$SendMail .= "</select><br />\n";
$SendMail .= "Your Name:<br/><input type='text' name='name' value=\"".$name."\" />\n";
$SendMail .= "Your Email Address:<br />\n";
$SendMail .= "<input type='text' name='email' size='40' value=\"".$email."\" />\n";
$SendMail .= "Subject:<br />\n";
$SendMail .= "<select name='subject'>\n";
    foreach ($subject_array as $value2) {
$SendMail .= "<option value=" . '"'. $value2 .'"' . ">" . $value2 . "</option>\n";
        }
$SendMail .= "</select><br />\n";
$SendMail .= "Message:<br />\n";
$SendMail .= "<textarea cols='50' rows='5' name='message'>".$message."</textarea><br />\n";
$SendMail .= "<input type='submit' value='Send' />&nbsp;&nbsp;\n";
$SendMail .= "<input type='reset' value='Reset' />\n";
$SendMail .= "</form>\n";
$SendMail .= "</div>\n";

return $SendMail;


#15 mikew

mikew

    Etomite Forum Newbie

  • Member
  • 36 posts

Posted 24 November 2004 - 04:09 AM

I am getting strange issue I am not sure how to fault find.
If I use the PHP function mail() the mail is sent no problems, but when I use the emailform the mail gets queued to my smtp but doesn't get delivered. Headers seem OK. The host won't accept and just disconects.

Where is the code for $sendmail?

Mike

#16 Guest_rthrash_*

Guest_rthrash_*
  • Guests

Posted 24 November 2004 - 04:25 AM

Do you have caching turned on on the page you're trying to use the form on? If so, turn it off... I ran into that one.

#17 mikew

mikew

    Etomite Forum Newbie

  • Member
  • 36 posts

Posted 24 November 2004 - 09:13 AM

Do you have caching turned on on the page you're trying to use the form on? If so, turn it off... I ran into that one.

Thanks tried that first up. I even tried enclosed in shrieks. I just think the bazar thing is I can place the follow code in a snippet and it works, but I use the emailfrom and the email goes to the queue andjust gets stuck in the queue

//mailtest
$message = "Test 99";
$sendfrom = "from:mike@poop.com.au";
mail("mike@bigpond.com","A Timesheet Has Been Submitted",$message,$sendfrom);


I think this started happening when I updated PHP to 4.3.9

#18 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 24 November 2004 - 02:16 PM

Thanks tried that first up. I even tried enclosed in shrieks.  I just think the bazar thing is I can place the follow code in a snippet and it works, but I use the emailfrom and the email goes to the queue  andjust gets stuck in the queue

//mailtest
$message = "Test 99";
$sendfrom = "from:mike@poop.com.au";
mail("mike@bigpond.com","A Timesheet Has Been Submitted",$message,$sendfrom);
I think this started happening when I updated PHP to 4.3.9

Try changing the code to "From: mike@poop.com.au\n" instead of "from:mike@poop.com.au"... Notice the space between the colon and the email address... You may also need to put "\n" after each header component... See if that helps... B)

#19 Guest_rthrash_*

Guest_rthrash_*
  • Guests

Posted 24 November 2004 - 04:00 PM

I bet that fixes it, good catch. I ran into that one, too!

#20 Guest_rthrash_*

Guest_rthrash_*
  • Guests

Posted 18 December 2004 - 02:53 PM

Some small updates for anyone that wants a form that validates:
// --------- Email Form (Etomite 0.6) ------------
// Version 0.6.4 - September 12, 2004 - Tony Summerville
// Modified 18-Dec-2004 by http://[DO NOT CIRCUMVENT THE WORD FILTER]/ to pass the W3C validators
//
// CSS classes used:
// .error {padding: 2px, background-color: #FFABAB; color; #000; border: 2px solid #f00}
// .message {padding: 2px, background-color: #3AF19D; color; #000; border: 2px solid #2CB777}
// .emailform -- actual wrapper-DIV for the form contents itself style as needed
//
// Config is down a bit....
///////////////////////////////////
// DO NOT MESS WITH THESE TWO LINES
$subject_array = array();
$recipient_array = array();
///////////////////////////////////
//  <-----  BEGIN CONFIG  ----->
// Edit only what's between the quotation marks in the below lines.
// These will be the subjects that your users can choose from
// You can have as many as you want.
// Each one must be set up like so:
// $subject_array[] = "What You Want This Choice To Be";
// Make sure to remove empty ones that you aren't using. Just delete the entire line.

$subject_array[] = "Subject1";
$subject_array[] = "Subject2";
$subject_array[] = "Subject3";
// add as many more as needed...

// The lines below contain the various people that can be contacted via your form.
// You can have as many as you want. Edit only the parts between the quotation marks set each one up as:
// $recipient_array["UNIQUE Short Name"] = "email@email.com";
// The "UNIQUE Short Name" will be shown in the select box.
// This allows the actual email address to be hidden from the user.
// Make sure to remove empty ones that you aren't using. Just delete the entire line.

$recipient_array["Person 1"] = '"someone@someplace.com"';
$recipient_array["Person 2"] = '"test@someplace.com"';
$recipient_array["Company"] = '"test2@someplace.com"';

// add as many more as you need

//  <-----  END CONFIG  ----->


if ($_POST['send'] == 'true') {
   $to = $_POST['to'];
   $name = $_POST['name'];
   $firm = $_POST['firm'];
   $email = $_POST['email'];
   $the_subject = $_POST['subject'];
   $message = $_POST['message'];
   if (($name == '') OR ($email == '') OR ($message == '')) {
       $SendMail .= '<div class="error">';
       $SendMail .= 'One of the fields was left blank. Please put fill in all fields.';
       $SendMail .= '</div>';
}
   elseif (ereg('([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)', $email)) {
       $recipient = $to;
       $subject = $the_subject;
       $additional_headers = "From: $email\r\n";
       $body = "Message from the website from:\n\nFirm: $firm\nName: $name\nEmail: $email\nSubject: $subject\n\nMessage:\n\n" . $message;
       if (mail($recipient, $subject, $body, $additional_headers)) {
           $SendMail .= "<div class='message'>";
           $SendMail .= "Message sent successfully!  Someone will contact you soon.";
           $SendMail .= "</div>";
           $name="";
           $firm="";
           $email="";
           $message="";
       } else {
           $SendMail .= "<div class='error'>";
           $SendMail .= "Error! Please try again.<br>";
           $SendMail .= "</div>";
           $send = "false";
       }
} else {
       $SendMail .= "<div class='error'>";
       $SendMail .= "The email address you supplied (".$email.") does not appear to be valid. Please try again.";
       $SendMail .= "</div>";
       $send = "false";
} 
} else {
   $SendMail .= "<p>Select your inquiry type from the box below and fill out the form.</p>";
}

$SendMail .= '<div class="emailform">';
$SendMail .= '<form name="emailform" method="post" action="">'."\n";
$SendMail .= '<input type="hidden" name="send" value="true" />'."\n";

$SendMail .= '<select name="to">'."\n";
   foreach ($recipient_array as $key => $value) {
       $SendMail .= "<option value=" . $value . ">" . $key . "</option>\n";
   }
$SendMail .= "</select><br />\n";
$SendMail .= 'Your Name:<br /><input type="text" name="name" value="'.$name.'" />'."\n<br />";
$SendMail .= 'Your Firm:<br /><input type="text" name="firm" value="'.$firm.'" />'."\n<br />";
$SendMail .= "Your Email Address:<br /> \n";
$SendMail .= "<input type='text' name='email' size='40' value=\"".$email."\" />\n<br />";
$SendMail .= "Subject:<br />\n";
$SendMail .= "<select name='subject'>\n";
   foreach ($subject_array as $value2) {
       $SendMail .= "<option value=" . '"'. $value2 .'"' . ">" . $value2 . "</option>\n";
   }
$SendMail .= "</select><br />\n";

$SendMail .= "Message:<br />\n";
$SendMail .= "<textarea cols='35' rows='5' name='message'>".$message."</textarea><br /><br />\n";
$SendMail .= "<input type='submit' value='Send' />&nbsp;&nbsp;";
// $SendMail .= "<input type='reset' value='Reset' />\n";
$SendMail .= "</form>\n";
$SendMail .= "</div>\n";

return $SendMail;

update: revise extra header to include \r\n and indented formatting

update 2 20-Dec-04: revise again to fix a few minor issues not working properly, thanks to Torben




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users