所以我将表格的内容邮寄给客户,他希望发送表格的人是Cc。
我做了一些研究,似乎我需要使用header
代码设置from,subject和cc,但我的代码设置不同 - 请参阅下文:
<?php
$relatedproduct = $_POST['related-product'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Phone: $phone \n About: $relatedproduct \n Message: $message";
$recipient = "email@mydomain.com";
$subject = "More information regarding $relatedproduct";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location: ' . $_SERVER['HTTP_REFERER']);
?>
可以这样做吗?
<?php
$relatedproduct = $_POST['related-product'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = $_POST['email'];
$subject = "More information regarding $relatedproduct";
$formcontent="From: $name \n Phone: $phone \n About: $relatedproduct \n Message: $message";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
// Mail it
mail($to, $subject, $formcontent, $headers);
?>
答案 0 :(得分:0)
是的,正如你所拥有的那样:
...
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthday@example.com' . "\r\n";
mail($to, $subject, $content, $headers);
?>
顺便提一下,请在注入POST变量之前清理它们(例如$to = $_POST['email'];
)。
正如@Rhopercy在评论中所说,也许电子邮件库可以帮助您,因为它可以为您处理大部分事情。请查看PHPMailer或SwiftMail。
答案 1 :(得分:0)
应该是这样的:
$relatedproduct = $_POST['related-product'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = "From: $email\r\nReply-To: $email";
$headers .= 'Cc: test@test.com\r\n';
$headers .= 'Bcc: test@test.com\r\n';
$headers .= "Return-Path: <info@premierinspectiontn.com>\r\n";
$to = $_POST['email'];
$subject = "More information regarding $relatedproduct";
$formcontent="From: $name \n Phone: $phone \n About: $relatedproduct \n Message: $message";
// Mail it
mail($to, $subject, $formcontent, $headers);