php邮件功能突然停止工作

时间:2014-03-09 13:23:11

标签: php function email

首先,我知道有像我这样的serval主题,但我无法理解,所以我开始这个话题。 我刚刚在这段代码中更改$from并再次撤消它但是在邮件功能无效后我尝试了错误报告,但是没有错误可以告诉我这段代码有什么问题吗?

<?php
    // Check if button name "Submit" is active, do this 
    if(isset($_POST['send']) && $_POST['send'] == 'Send')
     {

        for($i=0;$i<=$_SESSION["count"];$i++)
        {
            if(isset($_REQUEST['checkbox'][$i]))
            {
                $set_id = $_REQUEST['checkbox'][$i];

                $sql_new=mysql_query(" UPDATE `article` SET  `editor`='SENT'  WHERE `id`='$set_id' ", $connection);
                $article=$_REQUEST['file'][$i];
                $TOmail=$_REQUEST['editoremail'][$i];
            }
        }

        $subject ="Dear Colleague,";
        $message = "Please Read & Edit this Paper : {$article}
                    \n\n
                    \n Thanking you 
                    \n----------------- 
                    \n
                    \n Editorial Office ";
        $to = $TOmail;
        $from = "jept.ir";
        $headers = "From:" . "{$from}";
        $mail=mail($to,$subject,$message,$headers,$from);


        if(($sql_new) && ($mail)){
        $_SESSION["count"]="";
        echo "<div class='cleaner h30'></div>";
        echo "<b style='color:green;margin-left:10px;'>Article has sent to editor successfully!</b>";
        $sql_new='';
        echo "<meta http-equiv=\"refresh\" content=\"2;URL=editor.php\">";

         }
         else
         {
            echo "<div class='cleaner h30'></div>";
            echo "<b style='color:red;margin-left:10px;'>Something went wrong!</b>";
            $sql_new='';
            echo "<meta http-equiv=\"refresh\" content=\"2;URL=editor.php\">";                          
         }                      
        }
    ?> 

1 个答案:

答案 0 :(得分:0)

你没有在$message变量中关闭+你向mail()函数添加了错误的五个参数。你的标题也不完全正确。我编辑了你的mail()函数和具有utf8功能的$headers

$subject = "Dear Colleague";
$message = "Please Read & Edit this Paper : {$article}
            \n\n
            \n Thanking you 
            \n----------------- 
            \n
            \n Editorial Office ";
$to = $TOmail;
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-Type: text/html; charset = \"UTF-8\";\r\n";
$headers .= 'From: Jept.ir <email@jept.ir>' . "\r\n";        
$mail = mail($to, $subject, $message, $headers);