繁体   English   中英

邮件传递失败:向发件人返回邮件

[英]Mail delivery failed: returning message to sender

我想添加一条失败的邮件重定向到我的邮件脚本,这样如果用户在电子邮件字段中输入了错误的地址,它会返回给我,而不是我的托管公司的收件箱,我该怎么做? 我已经添加了返回路径但不起作用,我还能做些什么来使这段代码工作。

这是代码:

<?php if(isset($_POST['submit'])) { 
if(trim($_POST['first-name']) == '') {
    $hasError = true;
} else {
    $name = trim($_POST['first-name']);
}

//Check to make sure that the last name field is not empty
if(trim($_POST['last-name']) == '') {
    $hasError = true;
} else {
    $lname = trim($_POST['last-name']);
}

//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '')  {
    $hasError = true;
} else if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", trim($_POST['email']))) {
    $hasError = true;
    } else {
    $email = trim($_POST['email']);
}

//Check to make sure that the phone field is not empty
if(trim($_POST['tel']) == '') {
    $hasError = true;
} else {
    $phone = trim($_POST['tel']);
}

//Check to make sure that the phone field is not empty
if(trim($_POST['company']) == '') {
    $hasError = true;
} else {
    $company = trim($_POST['company']);
}



foreach (array($_POST['q1'])  as  $value)  {
 $q1 = $value[0];
 $q2 = $value[1];
 $q3 = $value[2];
}



//If there is no error, send the email
if(!isset($hasError)) {

    $to = 'me@host.com';
    $recipient = $email;


    $subject = 'Subject';

    $headers = "From: Me\n" . $to . "\r\n";
    $headers .= "Reply-To: ". $to . "\r\n";
    $headers .= "Return-Path: ". $to . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    $msg1 = "First Message";


    $msg2 = "Second Message";

    //Send Email
    mail($recipient, $subject, $msg2, $headers);
    mail($to, $subject, $msg1, $headers);

    $emailSent = true;
    }
}
?>

返回路径由mta根据信封发送方设置,您不能自己在标题中设置。 您可以尝试使用mail函数的$ additional_parameters参数设置信封发件人。 请参阅http://www.php.net/manual/en/function.mail.php上的示例#3

在你的情况下,这将是类似的

mail($recipient, $subject, $msg2, $headers, "-f $to");

在某些系统上,使用-f覆盖信封发件人是受限制的。 在这种情况下,您可能必须切换到通过SMTP提交邮件,而不是通过mail()调用sendmail二进制文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM