邮件传送失败:将邮件返回给发件人 [英] Mail delivery failed: returning message to sender

查看:157
本文介绍了邮件传送失败:将邮件返回给发件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个失败的消息重新直接添加到我的邮件脚本中,以便如果用户在电子邮件字段中输入错误的地址,那么它将返回给我,而不是托管公司的收件箱,我该怎么办那?我已经添加了返回路径但不起作用,还有什么可以让代码工作。

I would like to add a failed message re-direct to my mail script, so that if a user enters a wrong address in the email field it gets returned to me, and not to my hosting company's inbox, how do I do that? I've already added return-path but doesn't work, what else can i do to get this code to work.

这是代码:

<?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基于信封发件人,你不能只是自己在标题中设置。您可以尝试使用邮件功能的$ additional_parameters参数设置信封发件人。请参阅 http://www.php.net/manual/en/上的示例#3 function.mail.php

the return path is set by the mta based on the envelope sender, you can't just set that in the headers yourself. You can try to set the envelope sender using the $additional_parameters argument of the mail function. See Example #3 on http://www.php.net/manual/en/function.mail.php

在你的情况下,这将像

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

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

On some systems overriding the envelope sender using -f is restricted. In that case you'd probably have to switch to submitting the mail via SMTP instead of calling the sendmail binary via mail().

这篇关于邮件传送失败:将邮件返回给发件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆