我正在使用以下代码发送电子邮件,但不幸的是,电子邮件是以spam.check代码发送的,需要建议……我正在使用php mail()函数发送邮件。我做错了什么?这是不是正确的代码?电子邮件正在发送,但在收件箱中是垃圾邮件。所以我需要在我的代码中更正..
<?php
class mail
{
function setInput($data)
{
$data = trim($data);
$data = addslashes($data);
$data = htmlspecialchars($data);
return $data;
}
public function send($data)
{
$email_to = "xyz@gmail.com";
$email_subject=$this->setInput($data['Subject']);
$phone = $this->setInput($data['Phone']); // required
$email = $this->setInput($data['Email']); // required
$name = $this->setInput($data['Name']); // not required
$message = $this->setInput($data['Message']); // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Subject: ".clean_string($email_subject)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Comments: ".clean_string($message)."\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
echo "<script>
alert('Thank you for contacting us. We will be in touch with you very soon.');
window.location.href='contact.php';
</script>";
}
}
$objclass=new mail();
if(isset($_REQUEST['page_action']))
{
$page_action=$_REQUEST['page_action'];
switch($page_action)
{
case "email-msg";
$objclass->send($_POST);
break;
}
}
?>发布于 2020-12-31 15:07:04
请查收
您还需要检查该服务器的IP是否已被列入垃圾信息源黑名单。但请先检查上面的1和2。
另一种解决方案是通过SMTP服务器发送邮件。您可以使用PhpMailer来帮助您完成此操作(https://github.com/PHPMailer/PHPMailer)。如果您的SMTP服务器配置正确(且未被列入垃圾邮件来源黑名单),则发出的邮件将到达收件人收件箱,而不是垃圾邮件文件夹。
https://stackoverflow.com/questions/65517535
复制相似问题