How to test if PHP mail() has successfully delivered mail

后端 未结 8 1744
陌清茗
陌清茗 2020-12-18 20:01

How can I test if mail() has successfully delivered mail?

相关标签:
8条回答
  • 2020-12-18 20:43

    if (isset($_POST["btn_emp"])) {

    //$hid_emp = ($_POST['hid_emp']);
    $employee_name = ($_POST['employee_name']);
    $department_id = ($_POST['department_id']);
    $serial_number = ($_POST['serial_number']);
    $employee_address = ($_POST['employee_address']);
    $employee_contact = ($_POST['employee_contact']);
    $employee_email = ($_POST['employee_email']);
    
    
    
    
    
    $insert = "INSERT INTO tbl_employee(department_id,serial_number,employee_name,employee_address,employee_contact,employee_email)VALUES('$department_id', '$serial_number', '$employee_name','$employee_address' ,'$employee_contact', '$employee_email')";
    //echo $insert;
    //die();
    if ($conn->query($insert) === TRUE) {
        //CODE FOR SEND MAIL
        $Mail_Admin_Message = '';
                $Mail_Admin_Message .= '
                    <table width="700px" border="0" cellpadding="0" cellspacing="0">
    
                        <tr height="15px"><td colspan="3"></td></tr>
                        <tr>
                            <td colspan="3" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;">
                                Date</b> :<b> '. $serial_number .'</b>
                            </td>
                        </tr>
                        <tr height="15px"><td colspan="3"></td></tr>
                        <tr>
                            <td colspan="3" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;">
                                Hi</b> <b> '. $employee_name .'</b>
                            </td>
                        </tr>
                        <tr height="15px"><td colspan="3"></td></tr>
                        <tr>
                            <td colspan="3" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;">
                              Your Gift Voucher Code is</b> :<b> '. $department_id .'</b>
                            </td>
                        </tr>
                        <tr height="15px"><td colspan="3"></td></tr>
                        <tr>
                            <td colspan="3" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;">
                                Gift Amount</b> :<b> '. $employee_address .'</b>
                            </td>
                        </tr>
                        <tr height="15px"><td colspan="3"></td></tr>
                        <tr height="15px"><td colspan="3"></td></tr>
                        <tr>
                            <td colspan="3" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; font-weight:bold;">Thanks, <br />DairyKart Team</td>
                        </tr>
                    </table>';
    
                $Mail_To_Admin_ID   = $employee_email;
                $Mail_Admin_Subject = "Employee Details";
                $Mail_Admin_Header  = "MIME-Version: 1.0\n";
                $Mail_Admin_Header .= "Content-type: text/html; charset=iso-8859-1\r\n";
                $Mail_Admin_Header .= "Content-Transfer-Encoding: 8bit\n";
                $Mail_Admin_Header .= "X-Priority: 1\n";
                $Mail_Admin_Header .= "From: Employee-Department Project\r\n";
                $Mail_Admin_Header .= "X-MSMail-Priority: High\n";
                mail($Mail_To_Admin_ID, $Mail_Admin_Subject, $Mail_Admin_Message, $Mail_Admin_Header);
                //echo $serial_number;
                //echo $employee_email;
                //die();
        echo "<script>alert('Successfully Added & Check Your Mail to know your Details.!!!'); window.location='add-employee.php'</script>";
    
    0 讨论(0)
  • 2020-12-18 20:49

    Well mail() simply returns a boolean value depending on whether the mail was successfully accepted for delivery. From the php.net site:

    Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

    It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

    So you can test to see if it's been "sent", however checking if it's been delivered is another story.

    0 讨论(0)
提交回复
热议问题