Jump to content

Recommended Posts

I want to have a form with a drop down menu that decides who gets the email.  But I ALSO want the email to go to me.  Can anyone tell me the simplest way to go about this?

 

This is my form page:

 

	<form method="post" action="sendorderform.php">
  Email: <input name="email" type="text" /><br />
  Message:<br />
  <textarea name="message" rows="15" cols="40">
  </textarea><br />
  
  <select name='emailto' id='emailto'>
    <option value='me@yahoo.com'>man1@website.com</option>
    <option value='man2@website.com'>man2@website.com</option>
    <option value='man3@website.com'>man3@website.com</option>
    <option value='man4@website.com'>man4@website.com</option>
</select><br>
  
  <input type="submit" />
</form>

 

This is my php page:

 

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;
  $email_to = $_POST['emailto'] ;


  mail( $email_to, "Feedback Form Results",
    $message, "From: $email" );

?>

 

I actually got this to send per the drop down.  But, where do I put MY (fixed) email address to make it send TWO emails?  Thanks for any help!!!  I'm very new at this stuff.

Link to comment
https://forums.phpfreaks.com/topic/229948-going-insane-need-simple-form-help/
Share on other sites

You can add it as a BCC header:

 

mail( $email_to, "Feedback Form Results",
    $message, "BCC: me@mail.com\r\nFrom: $email" );

This way the other person should not see your email address or know you received a copy of it.

You could use CC: or TO: as well, but then the person you are sending it to would see your address.

 

I replaced my mail section:

  mail( $email_to, "Feedback Form Results",
    $message, "From: $email" );

 

with your mail section (put my email in instead of me@mail):

mail( $email_to, "Feedback Form Results",
    $message, "BCC: me@mail.com\r\nFrom: $email" );

 

and I'm still only getting the email to the drop down address.  Do I need to add more than that?  Thanks a ton for the help!

That should work. I'm pretty sure I've used it that way before. There are a couple of things to try:

 

1) Remove the carriage-return - the spec requires it but there are a few mail servers that do not handle it correctly.

2) Try swapping the From and the BCC sections

3) Try putting a CRLF pair after the From header

 

Actually, try #3 first:

mail( $email_to, "Feedback Form Results",
    $message, "BCC: me@mail.com\r\nFrom: $email\r\n" );

 

You know that is a backslash (before the "r" and the "n"), right? (don't mean to be insulting, just checking the obvious).

 

does it make any sense that this would only work if the two addresses (the drop down, and the bcc) are different?  I had them the same, thinking it would send 2 emails to my address... but it wouldn't work.  Then I changed the address on the drop down to my other email address and I got the email to both.  Is that possible that having the same address in both spots would stop it?

That is probably a mail server issue. It would make sense, to some degree, not to send extra emails. So, yeah, I could see the mail server deciding to send only one email if both addresses are the same. Since you got it to work with two different email addresses, it appears that the PHP mail() function is working as expected.

for sure!  I'm not complaining!  Thanks again for the help... long story short I'm trying to make this damn form work:  http://www.continentalrto.com/newfiles/orderform.html  I'm done with the form (except giving the fields better id's) and now I'm starting on constructing the php part of it.  Again... very new for me, but with the help of this site and Google, I hope I can figure it out.

 

My next question is how to make the "message" on this:

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;
  $email_to = $_POST['emailto'] ;


mail( $email_to, "Feedback Form Results",
    $message, "From: $email\r\nBCC: kalcotter1@yahoo.com\r\n" );

?>

 

have multiple lines and use the stuff from the form to make a somewhat readable email...  what's the best way to go about that?  I'm planning on making it read like:

------------------------------------------------

Someone just filled out the online order form!  Here's there info:

 

CUSTOMER INFORMATION

Renters Name:  (pull this part from the form)

Date of Birth: (pull this part from the form)

and so on.... 

-----------------------------------------------

 

Is there any way you could point me in the right direction?  Do I just put $_REQUEST['id_name'] wherever I want to post something from the form?  and how to I actually write "text" in a php email like this?  Not sure how to type a return, (like hitting enter while typing) either...  any help would be greatly appreciated!!!!!!!!!!!!  Thanks again for the help thus far.. I've been at this for 5 hours, and you did more in 10 minutes than I could find on Google all night!

There are a couple of ways to make a multiple line message.

 

You can just put a CRLF (or just a LF) at the end of each line:

$message = "Line 1\r\n";
$message .= "Line 2\r\n";

 

Or you can open the quotes on one line and close them on another:

$message = "Line 1
Line 2
";

 

You can use a HEREDOC

$message = <<EOT
Line 1
Line 2
$_POST['from_form']
EOT

(or something like that)

 

To add form fields, you can concatenate or place the variable inside a double-quoted string;

 

$message = "Line1 " . $_POST['from_form'] . PHP_EOL;
$message .= "Line 2 - {$_POST['fieldName']}" . PHP_EOL;

 

I tried taking what you said and putting it into code... I'm sure I did something wrong because it's not sending either email now...  This is what I did (I know I left my real email in there... I don't care)

<?php
  $email = $_REQUEST['email'] ;
  $email_to = $_POST['emailto'] ;
  
$message = "Someone just filled out the online order form!  Here's there info:\r\n";
$message .= "CUSTOMER INFORMATION\r\n";
$message .= "Renters Name - {$_POST['rname']}" . PHP_EOL;



mail( $email_to, "Online Application",
    $message, "From: $email\r\nBCC: kalcotter1@yahoo.com\r\n" );

?>

 

Any clue what I'm doing wrong?  Probably a few things I'm sure...  thanks!

The code looks OK. You might want to try just using new-lines ("\n") instead of the Carriage-return--new-line pair ("\r\n"). I usually just use PHP_EOL because it is defined as the appropriate line ending based on the system (unix/linux uses just \n while Windows uses \r\n). However, I can't remember what the mail specification says (I'm thinking just new-line). So your message might be:

 

  
$message = "Someone just filled out the online order form!  Here's there info:" . PHP_EOL;
$message .= "CUSTOMER INFORMATION" . PHP_EOL;
$message .= "Renters Name - {$_POST['rname']}" . PHP_EOL;

 

A couple of notes.

[*]The variables (i.e. $_POST) will ONLY be interpreted inside a double-quoted string. The code you posted is correct, but if you are using single quotes, in the actual script, it will not work (the "\r\n" will also ONLY work in double-quoted strings);

[*]Edit out your email address when you post code. I'm sure you don't want bots picking it up and spamming you;

[*]The address used for the From: header REALLY needs to be a valid email address on the server sending the email. Some servers will not send an email if the From does not belong to them (it looks like someone is forging mail); and some (most) servers will mark a message as spam if the From does not match the actual sending server.

[*]If the user provides an email address, and you want it in the email you get, add a Reply-To: header with their address. Then if you click reply, it will go to them. Of course, once you reply, they will have YOUR email address that you send it from.

It works!!!!!!! You rock dude!  Thanks for the advice also.    Can you tell me how to add a return?  or <br>?

 

$message = "Someone just filled out the online order form!  Here's there info:" . PHP_EOL;  ***EXTRA RETURN RIGHT HERE***
$message .= "CUSTOMER INFORMATION" . PHP_EOL;
$message .= "Renters Name - {$_POST['rname']}" . PHP_EOL;

Thanks!  I don't think it's an html email... not quite sure how to tell..  But, I tried this one... and it didn't work:

 

<?php
  $email = $_REQUEST['email'] ;
  $email_to = $_POST['emailto'] ;
  
$message = "Someone just filled out the online order form!  Here's there info:" . PHP_EOL; \n\n
$message .= "CUSTOMER INFORMATION" . PHP_EOL;
$message .= "Renters Name - {$_POST['rname']}" . PHP_EOL;



mail( $email_to, "Online Application",
    $message, "From: $email\r\nBCC: kalcotter1@yahoo.com\r\n" );

?>

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.