开发者

PHP email form CC

I have a very simple contact form on my site, Im looking for users to be able to just put a check mark next to "CC:" to have it CC them without creating a whole new field for that they have to fill out again.

Here is the HTML:

<form action="send.php" method="post" name="form1">
Name: <input name="name" size="35"><br/>
E-mail:<input name="email" size="35"><br/>
CC: <input input type="checkbox" name="mailcc"><br/>
Comment: <textarea cols="35" name="comment" rows="5"></textarea> <br />
<input name="Submit" type="submit" value="Submit">
</form>

And here is the PHP:

<?php
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$comment = $_REQUEST['comment'] ;

mail( "me@me.com", "Message Title",  "Name:  $name\n Email:  $email\n Comments: $comment\n " );

echo "Message Sent! Thanks!"

?>

Ive been trying to add some items from this site:

http://w3mentor.com/learn/php-mysql-tutorials/php-email/send-email-with-cccarbon-copy-bccblind-carbon-copy/

But it wants to create a text field for CC which means the user开发者_Go百科 would have to enter their email twice.

Ive also tried $mailheader.= "Cc: " . $email ."\n"; but I cant get that to work either.


  1. Make the checkbox have a value (value="1") in HTML.
  2. Add a variable ($mailheader) to the end of mail() function, as the last parameter.

So essentially:

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

if ($_POST['mailcc'] == 1) {
    $mailheader .= "CC: $name <$email>";
}

mail("me@me.com", "Message Title", "Name:  $name\n Email:  $email\n Comments: $comment\n ", $mailheader);

echo "Message Sent! Thanks!";


Is the Cc address you are testing with the same as the "to" address(me@me.com on your example)?

I did a quick test and with this code i get only one mail:

<?php
$to = "my@address.com";
$subject = "Testing";
$message = "Testing message";
$headers = "Cc: my@address.com";

mail($to, $subject, $message, $headers);

But with this i get a copy to my other email account:

<?php
$to = "my@address.com";
$subject = "Testing";
$message = "Testing message";
$headers = "Cc: my@otheraddress.com";

mail($to, $subject, $message, $headers);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜