邮件无法使用php发送

时间:2012-11-14 04:29:06

标签: php html email

希望我的所有专家都很好。 Buddy我陷入了一个非常简单的代码。实际上我必须插入一个表单,然后从中获取值以将邮件发送给填写表单的用户。所有值都插入到数据库中,并且还从数据库中获取但邮件未发送。一天前,同样的代码正在发送邮件。但今天它不发送邮件。请帮我解决这个问题。

<?php

    require("dbconnect.php");
    require("DBConnection.php");


    session_start();

    if(isset($_POST['postadd'])){

    $title = $_POST['adtitle'];
    $area = $_POST['area'];
    $addesc = $_POST['addesc'];
    $email = $_POST['email'];
    $showemail = $_POST['showemail'];
    $userpic = ($_FILES['pic1']['tmp_name']);
        $compath = "UploadPictures/".md5($_FILES['pic1']['name']);
        $comFileType=$_FILES['pic1']['type'];
        $comFileSize=$_FILES['pic1']['size'];
        $comFileSize=$comFileSize/1024;

            if($comFileSize<1000)
            {
                $arrFileType=array("image/jpeg","image/png","image/gif","image/bmp");
                if(in_array($comFileType,$arrFileType))

                {

                    move_uploaded_file($userpic,$compath);
                }
                else
                {
                    ("Invalid Image Format");   
                }
            }
            else
            {
                ("File Size Error");    
            }

            $pic2 = ($_FILES['pic2']['tmp_name']);
        $compath2 = "UploadPictures/".md5($_FILES['pic2']['name']);
        $comFileType2=$_FILES['pic2']['type'];
        $comFileSize2=$_FILES['pic2']['size'];
        $comFileSize2=$comFileSize2/1024;

            if($comFileSize2<1000)
            {
                $arrFileType2=array("image/jpeg","image/png","image/gif","image/bmp");
                if(in_array($comFileType2,$arrFileType2))

                {

                    move_uploaded_file($pic2,$compath2);
                }
                else
                {
                    ("Invalid Image Format");   
                }
            }
            else
            {
                ("File Size Error");    
            }

        $pic3 = ($_FILES['pic3']['tmp_name']);
        $compath3 = "UploadPictures/".md5($_FILES['pic2']['name']);
        $comFileType3=$_FILES['pic3']['type'];
        $comFileSize3=$_FILES['pic3']['size'];
        $comFileSize3=$comFileSize3/1024;

            if($comFileSize3<1000)
            {
                $arrFileType3=array("image/jpeg","image/png","image/gif","image/bmp");
                if(in_array($comFileType3,$arrFileType3))

                {

                    move_uploaded_file($pic3,$compath3);
                }
                else
                {
                    ("Invalid Image Format");   
                }
            }
            else
            {
                ("File Size Error");    
            }

        $pic4 = ($_FILES['pic4']['tmp_name']);
        $compath4 = "UploadPictures/".md5($_FILES['pic4']['name']);
        $comFileType4=$_FILES['pic4']['type'];
        $comFileSize4=$_FILES['pic4']['size'];
        $comFileSize4=$comFileSize4/1024;

            if($comFileSize4<1000)
            {
                $arrFileType4=array("image/jpeg","image/png","image/gif","image/bmp");
                if(in_array($comFileType4,$arrFileType4))

                {

                    move_uploaded_file($pic4,$compath4);
                }
                else
                {
                    ("Invalid Image Format");   
                }
            }
            else
            {
                ("File Size Error");    
            }
        $agree = $_POST['checkbox'];
        $subcat = $_SESSION['subcat'];
        $cat = $_SESSION['cat'];
        $rand = rand();
        $datecreated = date("Y-m-d h:i:s");

            $obj = new DBConnection();
            $arr_Field = array("title","location","post","email","radio","pic1","pic2","pic3","pic4","agree","cat","subcat","random","datecreated");
            $arr_values = array("$title","$area","$addesc","$email","$showemail","$compath","$compath2","$compath3","$compath4","$agree", "$cat", "$subcat" ,"$rand","$datecreated");
            $obj->InsertRecord("ads",$arr_Field,$arr_values) or die (mysql_error());

            $object = new DBConnection();
                $condition = "ORDER BY id DESC LIMIT 1";
                $selquery = $object->SelectRecord(array("*"),"ads","$condition") or die(mysql_error()); 
                while($get = mysql_fetch_array($selquery)){
                $email = $get['email'];
                $id = $get['id'];
                }
                //echo $email;
                //exit();

$to = $email;
$subject = "Admin";

$message = "
<html>
<head>
<title>Admin</title>
</head>
<body>
<p>Please Click on this Link to verify your post</p>
<p><a href='http://almughnisolutions.com/almughniclassified/summary.php?summary=".$id."'>http://almughnisolutions.com/almughniclassified/summary.php?summary=".$id."</a></p>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From: <admin@almughniclassfied.com>' . "\r\n";

mail($to,$subject,$message,$headers) or die("Mail Cannot sent");

            //header("Location:verifyadd.php");

    }

    ?>

1 个答案:

答案 0 :(得分:1)

这可能是一个安全的假设,你的代码不应该受到责备。如果SMPT服务器的行为正确,那么粗略地回顾一下它似乎很有用。我建议测试服务器。有一些基于Web的工具可以做到这一点:

https://www.wormly.com/test_smtp_server

如果需要在内部完成某些操作,您也可以使用telnet从您的机器进行测试:

http://technet.microsoft.com/en-us/library/aa995718%28v=exchg.65%29.aspx