PHP 电子邮件表格抄送

发布于 2024-10-16 22:12:28 字数 1298 浏览 3 评论 0原文

我的网站上有一个非常简单的联系表单,我希望用户只需在“抄送:”旁边打勾即可抄送他们,而无需创建一个全新的字段,因为他们必须再次填写。

这是 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>

这是 PHP:

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

mail( "[email protected]", "Message Title",  "Name:  $name\n Email:  $email\n Comments: $comment\n " );

echo "Message Sent! Thanks!"

?>

我一直在尝试从该站点添加一些项目:

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

但它想要为 CC 创建一个文本字段,这意味着用户必须输入电子邮件两次。

我也尝试过 $mailheader.= "Cc: " 。 $email ."\n"; 但我也无法让它工作。

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( "[email protected]", "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 would have to enter their email twice.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弃爱 2024-10-23 22:12:28
  1. 使复选框具有 HTML 中的值 (value="1")。
  2. 将变量 ($mailheader) 添加到 mail() 函数的末尾,作为最后一个参数。

所以本质上是:

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

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

mail("[email protected]", "Message Title", "Name:  $name\n Email:  $email\n Comments: $comment\n ", $mailheader);

echo "Message Sent! Thanks!";
  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("[email protected]", "Message Title", "Name:  $name\n Email:  $email\n Comments: $comment\n ", $mailheader);

echo "Message Sent! Thanks!";
雪花飘飘的天空 2024-10-23 22:12:28

您正在测试的抄送地址是否与“收件人”地址相同([email protected ] 在你的例子中)?

我做了一个快速测试,使用此代码我只收到一封邮件:

<?php
$to = "[email protected]";
$subject = "Testing";
$message = "Testing message";
$headers = "Cc: [email protected]";

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

但是通过此我得到了一份副本到我的其他电子邮件帐户:

<?php
$to = "[email protected]";
$subject = "Testing";
$message = "Testing message";
$headers = "Cc: [email protected]";

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

Is the Cc address you are testing with the same as the "to" address([email protected] on your example)?

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

<?php
$to = "[email protected]";
$subject = "Testing";
$message = "Testing message";
$headers = "Cc: [email protected]";

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

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

<?php
$to = "[email protected]";
$subject = "Testing";
$message = "Testing message";
$headers = "Cc: [email protected]";

mail($to, $subject, $message, $headers);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文