简体   繁体   English

如何设置发件人的电子邮件仅从特定域发送?

[英]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.

相关问题 通过SMTP发送电子邮件,不会更改发件人的域? - Send email over SMTP not changing sender's domain? 如何从PHP中的电子邮件ID数组检查具有特定域的电子邮件ID? - How to check email id's with specific domain from the array of email id's in PHP? 使用域验证电子邮件发件人 - Authenticating an email sender with a domain PHP电子邮件表格,如何绕过主机限制? (只能发送/接收IF主机发送者/接收者) - PHP email form, how to bypass host limitation? (Can ONLY send/receive IF hosting sender/receiver) 仅当输入的电子邮件来自特定域时才执行脚本 - Only execute script if entered email is from a specific domain 如何将 PHP / HTML 表格的副本发送到发件人的 email 地址? - How can I send a copy of a PHP / HTML form to the sender's email address? 如何使用文本框将 HTML 表格的副本发送到发件人的 email? - How can I send a copy of an HTML form to the sender's email using a text box? PHP PEAR send_mail无法使用姓名和电子邮件设置发件人 - PHP PEAR send_mail Failed to set sender with name and email 我们如何使用多个电子邮件帐户作为发件人发送电子邮件 - how we can send email with multiple email account as sender 如何从特定的IP地址发送电子邮件? - How to send email from a specific ip address?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM