通过php发送邮件,格式错误的回复

时间:2014-10-16 09:17:35

标签: php email sendmail

由于我们在使用gmails垃圾邮件过滤器时遇到问题,我不得不修改我们的俱乐部活动日历。 我尝试修改以下代码,以便发件人电子邮件现在是"回复"而来自" calendar@dsac.co.uk"希望使用我们自己域名的电子邮件解决垃圾邮件问题。邮件无法发送,我收到此错误"回复:丢失或格式错误的本地部分(预期的字或"<")"

我已尝试将回复电子邮件更改为但结果相同。我正在学习php,而且这些代码都不是我的,我只是想让它工作。

以下是我修改的代码。

<?php
require('wordpress/wp-load.php');
get_header();
?>

<div id="container">
  <div id="content" role="main">

<?php
include ("inc/functions.inc");
include ("inc/dbconnect.inc");

$db = db_connect();

$cookie = $_COOKIE[User];
$cookiearray = explode(",",$cookie);
if (isset($_POST['to'])){
    $particode = $_POST['IDs'];
    $participants = explode(",",$particode);
    $search = "";
    $numpar = count($participants)-1;
    for ($i=0;$i<=$numpar;$i++){
        if ($search == ""){
            $search = "ID LIKE ".$participants[$i];
        }else {
            $search = $search." OR ID LIKE ".$participants[$i];
        }
    }
    $result = mysql_query("SELECT Mail FROM users WHERE ".$search, $db);
    if (!$result) {
       die('Invalid query: ' . mysql_error());
    }
    $msg = $_POST['msg'];
    $subject = $_POST['subject'];
    $numpar = mysql_num_rows($result)-1;
    for ($i=0;$i<=$numpar;$i++){
        if ($i == 0){
            $to = mysql_result($result,$i,'Mail');
        }else {
            $to = $to.", ".mysql_result($result,$i,'Mail');
        }
    }
    $result = mysql_query("SELECT Mail FROM users WHERE ID LIKE ".$cookiearray[0], $db);
    if (!$result) {
       die('Invalid query: ' . mysql_error());
    }
    $replyto = mysql_result($result,0,'Mail');


    $from = 'calendar@dsac.co.uk';

    $test = mail($to, $subject, $msg,'From: '.$from,'Reply-To: '.$replyto);


    if ($test){
        Echo "<b>Mail sent</b>";
    }else{
        echo "<b>An error has occured trying to send your mail, sorry</b>";
    }
}Else {
    $particode = $_POST['participants'];
    $participants = explode(",",$particode);
    $search = "";
    $numpar = count($participants)-1;
    for ($i=0;$i<=$numpar;$i++){
        if ($search == ""){
            $search = "ID LIKE ".$participants[$i];
        }else {
            $search = $search." OR ID LIKE ".$participants[$i];
        }
    }
    $result = mysql_query("SELECT Name FROM users WHERE ".$search, $db);
    if (!$result) {
       die('Invalid query: ' . mysql_error());
    }
    Echo "<form name='mailform' action='eventmail.php' method='POST'>\n
    <table border='0'>\n
    <tr><td><b>To:</b></td><td><textarea rows='2' cols='45' name='to' readonly>";
    for ($i=0;$i<=$numpar;$i++){
        if ($i == 0){
            echo mysql_result($result,$i,'Name');
        }else {
            echo "; ".mysql_result($result,$i,'Name');
        }
    }
    Echo "</textarea><input type='hidden' name='IDs' value='".$particode."'></td></tr>\n
    <tr><td valign='top'><b>Subject:</b></td><td><input type='text' name='subject' size='45'></td></tr>\n
    <tr><td valign='top'><b>Message:</b></td><td><Textarea name='msg' rows='20' cols='45'></textarea></td></tr>\n
    <tr><td colspan=2 valign='top'><input type='submit' value='Send mail'></td></tr></table>\n
    </form>
    ";
}

?>

</div>
</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

感谢。

1 个答案:

答案 0 :(得分:0)

尝试使用此标题可能有效。

$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "From: $brand_name <$from>";
$headers[] = "Bcc: Name <name@domain.com>";
$headers[] = "Reply-To: Recipient Name <receiver@domain3.com>"; 
$headers[] = "Subject: {$subject}";
$headers[] = "Return-Path: <$from>";
$headers[] = "X-Priority: 3";//1 = High, 3 = Normal, 5 = Low
$headers[] = "X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, implode("\r\n", $headers));