[英]How to set sender's email send from specific domain only?
For example, i only want the sender's email is from "anything@abc.com", if other email like "anything@cde.com" is not allow, only @abc.com is allowed. 例如,我只希望发件人的电子邮件来自“ anything@abc.com”,如果不允许其他电子邮件(如“ anything@cde.com”),则仅允许@ abc.com。 How should i do that? 我该怎么办?
let say $_POST['Sender']="anything@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.";
you should be able to just wrap it within an if statement: 您应该可以将其包装在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.";
}
You can use PHP's strstr
function to strip the first part of the email off (everything before @) like so: 您可以使用PHP的strstr
函数剥离电子邮件的第一部分(@之前的所有内容),如下所示:
$from = strstr($_POST["Sender"], "@");
if($from == "@abc.com") {
// send mail
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
See http://php.net/manual/en/function.strstr.php for more information on the strstr
function 有关strstr
函数的更多信息,请参见http://php.net/manual/en/function.strstr.php 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.