Php邮件不发送邮件

时间:2015-03-16 11:30:07

标签: php email

我正在尝试使用以下php脚本发送邮件,但邮件没有通过....脚本运行到最后但没有发送邮件, 如果要发送邮件,调试的最佳方法是什么?

$link = $this->db_connection();
        $enc_password = md5($password);

        //checking if the username is available in the table
        $result = mysqli_query($link, "SELECT concat(users.title,' ',users.f_name,' ',users.s_name,' ',users.o_name) as fullname, user_id,user_name,role_id,status from users WHERE email='$emailusername' or user_name='$emailusername' and password='$enc_password'");
        $user_data = mysqli_fetch_array($result, MYSQLI_BOTH);
        $count_row = mysqli_num_rows($result);
        $base_url = $this->url();
        if ($count_row == 1) {
            if ($password === "123456") {

                //set the random id length 
                $random_id_length = 10;
                $today = date("Y-m-d H:i:s");
                //generate a random id encrypt it and store it in $rnd_id 
                $rnd_id = crypt(uniqid($today, 1));
                //to remove any slashes that might have come 
                $rnd_id = strip_tags(stripslashes($rnd_id));

                //Removing any . or / and reversing the string 
                $rnd_id = str_replace(".", "", $rnd_id);
                $rnd_id = strrev(str_replace("/", "", $rnd_id));

                //finally I take the first 10 characters from the $rnd_id 
                $random_key = substr($rnd_id, 0, $random_id_length);

                $email = $user_data['email'];
                $username = $user_data['username'];
                $user_id = $user_data['user_id'];
                $full_name = $user_data['fullname'];
                $headers = "From: webmaster@emarps.org" . "\r\n" .
                        "CC: harrisdindisamuel@gmail.com";
                $subject = "Reset User Account Password";
                // the message
                $msg = '
                                                                           ---------------------
                                                                                Hey :' . $full_name . '!
                                                                                    <fieldset>
                                                                                We currently received a request for resetting your EMARPS  ACCOUNT Password. You can reset your   Personal Account Password 
                                                                                through the link below:
                                                                                <hr>
                                                                                ------------------------
                                                                                Please click this link to activate your account:<a href="' . $base_url . 'resetpassword.php?uq=/' . $random_key . '">Reset</a>


                                                                                ------------------------ ';
                ;

                // use wordwrap() if lines are longer than 70 characters
                // $msg = wordwrap($msg, 70);
                // send email
                mail($email, $subject, $msg, $headers);

            }

确定邮件功能是否正常/邮件是否通过的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

使用简单的if语句:

if(mail($email, $subject, $msg, $headers)) {
    echo 'Mail send!';
}

http://php.net/manual/en/function.mail.php

  

如果邮件成功接受传递,则返回TRUE,FALSE   否则。

     

重要的是要注意,因为邮件被接受了   交付,并不意味着邮件实际上会达到预期的目的   目的地。

您只能检查邮件服务器是否排除了邮件,如果邮件是真的已经发送,您只能在邮件服务器(mailq)中检查该案例,或者使用所有退回邮件到达的返回邮件地址检查邮箱,并检查收件箱。它有点复杂。