Jump to content

Field Not Sticky


doubledee

Recommended Posts

I have a form where users can send comments.  The form sends the comments to me via e-mail.

 

Why is the e-mail field not staying "sticky" after I click "Submit" yet the other fields are??

<form id="comments" action="" method="post">
	<ul>
		<!-- Sender's Email -->
		<li>
			<label for="senderEmail">Your E-mail:</label>
			<input id="senderEmail" name="senderEmail" class="text" type="text" maxlength="40"
				 value="<?php if(isset($senderEmail)){echo htmlspecialchars($senderEmail, ENT_QUOTES);} ?>" /><!-- Sticky Field -->
			<?php
				if (!empty($errors['senderEmail'])){
					echo '<span class="error">' . $errors['senderEmail'] . '</span>';
				}
			?>
		</li>

		<!-- Subject Line -->
		<li>
			<label for="subject">Subject:</label>
			<input id="subject" name="subject" class="text" type="text" maxlength="80"
				 value="<?php if(isset($subject)){echo htmlspecialchars($subject, ENT_QUOTES);} ?>" /><!-- Sticky Field -->
			<?php
				if (!empty($errors['subject'])){
					echo '<span class="error">' . $errors['subject'] . '</span>';
				}
			?>
		</li>

 

 

 

Debbie

 

Link to comment
Share on other sites

Have you tried echoing $senderEmail to see if it actually contains a value?

 

Good point.  I actually deleted this line by accident...

$senderEmail = $trimmed['senderEmail'];

 

 

BTW, can you help me figure this out...

 

How do I get e-mails from this form to appear like this in my inbox...

To:	debbie@mail.com
From:	some_user@yahoo.com
Date:	10/11/2011
Re:	I really like your website

Hey Debbie,

Just checked out your website and I love it!

Keep up the good work!

Sincerely,


Some User

 

I'm a bit confused how the mail() function works and why it asks for values that seem unintuitive?!

 

 

Debbie

 

Link to comment
Share on other sites

What - specifically - are you having trouble understanding? Email is, in my opinion, can be one of the more complex tasks IF you need to make it complex. But, for a simple plain-text email the description and examples in the manual are easy enough to follow. I don't know that anyone could provide a more thorough explanation in a forum post.

 

I assume you understand the first three parameters (which are required): $to , $subject , $message. The manual gives a good explanation of how the data in those parameters should be formatted.

 

The last two parameters ($additional_headers and $additional_parameters) are probably where your confusion is. The first one shuld typically be considered required because you must set a "from" address. If it is not set in the php.ini file, then you must set it is this parameter. The manual also explains some other headers that can be set: CC, BCC, Reply-To, etc. But, there are numerous headers and parameters that can be set. To be honest I have never found a definitive list of what options can be set. That is probably because those values are not dictated by PHP but by the original classifications for email communications. In fact, I would guess that some parameters may be valid for some email servers and not others.

Link to comment
Share on other sites

What - specifically - are you having trouble understanding? Email is, in my opinion, can be one of the more complex tasks IF you need to make it complex. But, for a simple plain-text email the description and examples in the manual are easy enough to follow. I don't know that anyone could provide a more thorough explanation in a forum post.

 

I assume you understand the first three parameters (which are required): $to , $subject , $message. The manual gives a good explanation of how the data in those parameters should be formatted.

 

The last two parameters ($additional_headers and $additional_parameters) are probably where your confusion is. The first one shuld typically be considered required because you must set a "from" address. If it is not set in the php.ini file, then you must set it is this parameter. The manual also explains some other headers that can be set: CC, BCC, Reply-To, etc. But, there are numerous headers and parameters that can be set. To be honest I have never found a definitive list of what options can be set. That is probably because those values are not dictated by PHP but by the original classifications for email communications. In fact, I would guess that some parameters may be valid for some email servers and not others.

 

Well, one thing I'm unclear on is why someone else made the "From" parameter look like this...

 

$headers .= 'From:  <"'.$from.'">' . "\r\n";

 

Why are they adding the text 'From"??

 

And why isn't From a required parameter like To??

 

 

Debbie

 

Link to comment
Share on other sites

Well, one thing I'm unclear on is why someone else made the "From" parameter look like this...

 

$headers .= 'From:  <"'.$from.'">' . "\r\n";

 

Why are they adding the text 'From"??

 

And why isn't From a required parameter like To??

 

I thought I tried to explained that. The mail() function is built to work with the existing email standards. The manual even provides a link to those standards if you are so inclined to read them. The format for the FROM value (and all the other values) is dictated by those standards which have nothing to do with PHP. And, the FROM does NOT have to be in that format (i.e with the <>). That format is only required if you want to include a "friendly name" along with the email address. The reason they are adding the text "From:"? The $headers parameter can take many different values. If you don't specify the name of the header for the value how are the email servers supposed to know what it is?

 

As stated previously you can set the from value in the php.ini file, in which case it isn't required for you to set it in the $headers parameter. So, if you were to set a value of "me@mydomain.com" without naming the header it is for, it could be the FROM address, the Return address, or a CC, or BCC, etc.

 

I guess they didn't make it "Englishy" enough.

Link to comment
Share on other sites

Well, one thing I'm unclear on is why someone else made the "From" parameter look like this...

 

$headers .= 'From:  <"'.$from.'">' . "\r\n";

 

Why are they adding the text 'From"??

 

And why isn't From a required parameter like To??

 

The reason they are adding the text "From:"? The $headers parameter can take many different values. If you don't specify the name of the header for the value how are the email servers supposed to know what it is?

 

Okay, that makes sense.

 

 

I guess they didn't make it "Englishy" enough.

 

No, I'm just a newb.  ;D

 

Thanks,

 

 

Debbie

 

Link to comment
Share on other sites

BTW, can you help me figure this out...

 

How do I get e-mails from this form to appear like this in my inbox...

 

 

To: debbie@mail.com

From: some_user@yahoo.com

Date: 10/11/2011

Re: I really like your website

 

Hey Debbie,

 

Just checked out your website and I love it!

 

Keep up the good work!

 

Sincerely,

 

 

Some User

 

Not sure where you're at on this but I use an email version "like" this all the time.    By all means use a plain text email if you want but I thought I'd give you another option.  I use an html format and  I also usually have a header image and a footer to my table but you should get the idea from this.  The nested tables are in the layout as I read somewhere that it translates across platforms better (for centering email when header image is used).

<?php
/*Not knowing the variables you are using I will put
$sendername  //The name of person sending email 
$senderemail //The senders email
$msgsubject	 //The subject line
$message	 //The sender message
$siteemail  //Site email address you've setup on your server for sending email
$myemail //  I assume you're sending to yourself
*/
$mailmsg="<p>To:  $myemail<br />From:  $senderemail<br />Date:  10/11/2011<br />Re:  $msgsubject<br /><br />$message</p>";
     $mail_to = "$myemail";
     $mail_subject = "$subject";
     $mail_body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head><body><center><table width=98% border=\"0\" align=\"center\" cellpadding=1 cellspacing=\"0\" ><tr><td align=\"center\" valign=\"top\"><table width=98% border=\"0\"  cellpadding=\"0\" cellspacing=\"0\"><tr><td bgcolor=\"#FFFFFF\" align=\"left\" style=\"padding:14px;\">$mailmsg</td></tr></table></td></tr></table></center></body></html>";
$headers = "From: $siteemail\r\n";
$headers .= "Reply-To: $senderemail\r\n";
$headers .= "Organization: $sendername \r\n";
$headers .= "X-Sender: $siteemail \r\n";
$headers .= "X-Priority: 3 \r\n";
$headers .= "X-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  mail($mail_to, $mail_subject, $mail_body, $headers);
?>

Link to comment
Share on other sites

Drummin,

 

<?php
/*Not knowing the variables you are using I will put
$sendername  //The name of person sending email 
$senderemail //The senders email
$msgsubject	 //The subject line
$message	 //The sender message
$siteemail  //Site email address you've setup on your server for sending email
$myemail //  I assume you're sending to yourself
*/

 

I'm not following what the purpose of $sitemail and $myemail and $senderemail is??

 

 

$mailmsg="<p>To:  $myemail<br />From:  $senderemail<br />Date:  10/11/2011<br />Re:  $msgsubject<br /><br />$message</p>";
     $mail_to = "$myemail";
     $mail_subject = "$subject";
     $mail_body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head><body><center><table width=98% border=\"0\" align=\"center\" cellpadding=1 cellspacing=\"0\" ><tr><td align=\"center\" valign=\"top\"><table width=98% border=\"0\"  cellpadding=\"0\" cellspacing=\"0\"><tr><td bgcolor=\"#FFFFFF\" align=\"left\" style=\"padding:14px;\">$mailmsg</td></tr></table></td></tr></table></center></body></html>";
$headers = "From: $siteemail\r\n";
$headers .= "Reply-To: $senderemail\r\n";
$headers .= "Organization: $sendername \r\n";
$headers .= "X-Sender: $siteemail \r\n";
$headers .= "X-Priority: 3 \r\n";
$headers .= "X-Mailer: php\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  mail($mail_to, $mail_subject, $mail_body, $headers);
?>

 

What are you trying to accomplish with...

 

Reply-To??

 

Organization??

 

X-Sender??

 

X-Priority??

 

X-Mailer??

 

MIME-Version??

 

Content-Type??

 

 

 

Debbie

 

Link to comment
Share on other sites

I'm not following what the purpose of $sitemail and $myemail and $senderemail is??

 

These were explained here.  AND these were just samples so if you wish to add values directly instead of setting variables, fine.

 

$sendername  //The name of person sending email

$senderemail //The senders email

$msgsubject //The subject line

$message //The sender message

$siteemail  //Site email address you've setup on your server for sending email

$myemail //  I assume you're sending to yourself

 

I'm no expert when it comes to email headers and so some of this was a result of complying with my hosting.  You are sending an email from your site, so if you haven’t created an email account you should.  This would be the variable $siteemail.

 

$myemail is simply your email address.  You can add this directly instead of using the variable.

 

$senderemail is the email you're gathering from your form from the person.

 

Again, these variables can be changed as you wish I was just giving an example.

As far as these headers, I looked at many examples and this is what I'm using.

 

headers = "From: $siteemail\r\n";

So you are sending from your site email address.

 

$headers .= "Reply-To: $senderemail\r\n";

The reply-To has the users email address so when you click "Reply" when reading the email you will be writing to the user.

 

$headers .= "Organization: $sendername \r\n";

If you add the Organization heading you will see this name shown as the "from" name, i.e. From Sam Smith.

 

$headers .= "X-Sender: $siteemail \r\n";

For many hosting services this is required as a point of validation.  It should match the email account you set up.

 

$headers .= "X-Priority: 3 \r\n";

This is the most common way of setting the priority of an email. "1" is High, "3" is normal, and "5" is the lowest.

 

$headers .= "X-Mailer: php\r\n";

I believe this indicates the type of program being used to send email.

 

$headers .= "MIME-Version: 1.0\r\n";

Not sure but I believe it has to do with character set and by setting this, clients view the message the same way.

 

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

This tells the client this is an html email.

 

You can find many example of email headers by searching for it.

 

Link to comment
Share on other sites

Drummin,

 

I'm no expert when it comes to email headers and so some of this was a result of complying with my hosting.  You are sending an email from your site, so if you haven’t created an email account you should.  This would be the variable $siteemail.

 

$myemail is simply your email address.  You can add this directly instead of using the variable.

 

If I have "debbie@mycompanyname.com" then I should be able to use that for both $siteEmail and $myEmail, right??

 

 

headers = "From: $siteemail\r\n";

So you are sending from your site email address.

 

$headers .= "Reply-To: $senderemail\r\n";

The reply-To has the users email address so when you click "Reply" when reading the email you will be writing to the user.

 

Again, I'm confused here.

 

Why would you have two e-mail addresses?

 

You make it sound like there is some generic e-mail out there associated with your domain, which seems strange.

 

When I got my domain name, there was no default e-mail.  I had to create one, and so I created "debbie@mydomain.com"

 

 

headers = "From: $siteemail\r\n";

 

If someone is filling out a Comments Form, then shouldn't the "From" be from them and not me?

 

And is the reason you have 'From: ' in there so that the mail application knows which parameter the address relates to?

 

 

$headers .= "Reply-To: $senderemail\r\n";

The reply-To has the users email address so when you click "Reply" when reading the email you will be writing to the user.

 

If I left that out, what would happen?

 

If my Comments Form has

headers = "From: $senderEmail\r\n";

then wouldn't my e-mail application key off of that and know who to reply to?

 

 

$headers .= "Organization: $sendername \r\n";

If you add the Organization heading you will see this name shown as the "from" name, i.e. From Sam Smith.

 

I'm getting more confused here... 

 

Is Organization like this...

 

'John Doe' <john.doe@gmail.com>

 

 

 

$headers .= "X-Sender: $siteemail \r\n";

For many hosting services this is required as a point of validation.  It should match the email account you set up.

 

Again, couldn't I use "debbie@mydomain.com" since it would be me replying?

 

 

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

This tells the client this is an html email.

 

What do I do if I just want to send a text e-mail response?

 

 

Debbie

 

 

Link to comment
Share on other sites

Yes Debbie,  Many of the variables I used in the example can be placed directly like debbie@mydomain.com.

If I have "debbie@mycompanyname.com" then I should be able to use that for both $siteEmail and $myEmail, right??

These two distinctions is assuming you are not sending the email to your domain email account and "$myEmail" might be a private email account.

 

You make it sound like there is some generic e-mail out there associated with your domain, which seems strange.

 

When I got my domain name, there was no default e-mail.  I had to create one, and so I created "debbie@mydomain.com"

Absolutely, which is why I said

if you haven’t created an email account you should.

 

If my Comments Form has

Code: [select]

 

headers = "From: $senderEmail\r\n";

 

then wouldn't my e-mail application key off of that and know who to reply to?

Assuming your host is going to allow you to send emails from an unverified email address and not the address you set up debbie@mydomain.com, then clicking "Reply" would be sending to the "FROM" address.  Adding a Reply-To: $senderemail address allows you to reply to the address specified.

 

Quote

 

    $headers .= "X-Sender: $siteemail \r\n";

    For many hosting services this is required as a point of validation.  It should match the email account you set up.

 

 

Again, couldn't I use "debbie@mydomain.com" since it would be me replying?

Again, these variables are just samples.  Put what you want there.

What do I do if I just want to send a text e-mail response?
Then forget this whole discussion and add  \r\n for line breaks.  I was just giving you an html sample.
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.