例如,我只希望发件人的电子邮件来自“anything@abc.com”,如果不允许其他电子邮件如“anything@cde.com”,则只允许使用@ abc.com。我该怎么做?
让我们说$ _POST ['Sender'] =“anything@abc.com”;
$to = "someone@example.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = $_POST['Sender']; $headers = "From:" . $from; mail($to,$subject,$message,$headers); echo "Mail Sent.";
答案 0 :(得分:0)
你应该能够将它包装在if语句中:
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $_POST['Sender'];
$headers = "From:" . $from;
if ($from === "anything@abc.com") {
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
答案 1 :(得分:0)
您可以使用PHP的strstr
功能删除电子邮件的第一部分(@之前的所有内容),如下所示:
$from = strstr($_POST["Sender"], "@");
if($from == "@abc.com") {
// send mail
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
有关strstr
功能