我在php邮件函数中发送cc以从客户端获得反馈时遇到问题。这里有一个简单的php代码-
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["name"]==""||$_POST["email"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['email'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Invalid Sender's Email";
}
else{
$subject = $_POST['sub'];
$name = $_POST["name"];
$message = $_POST['msg'];
$headers = 'From:'. $email . "rn"; // Sender's Email
$headers .= 'Cc:'. $email . "rn"; // Carbon copy to Sender
// Send Mail By PHP Mail Function
mail("xyz@example.com", $subject, $message, $headers);
echo "Your mail has been sent successfuly !";
}
}
}
?>
邮件已正确发送给发件人,但未发送抄送。此外,当我在"抄送"字段中固定电子邮件地址时,即abc@xxx.com而不是$email,则抄送起作用。帮我解决这个问题。
我以前对此有很多麻烦。尝试安装php邮件插件
https://github.com/PHPMailer/PHPMailer.
这也将防止未来的问题,并在你意识到你可能想从发送电子邮件中获得更多时为你节省大量时间。