PHP电子邮件不发送或发送回显的消息

时间:2015-08-13 21:09:46

标签: php email

我创建了这封电子邮件,由于某种原因它没有发送。我得到的唯一错误是解析错误,即文件意外结束。出于某种原因,我没有收到成功或失败的消息......

顶部变量是我通过AJAX调用发送的值。

if(mail($to,$subject,$message,$headers)){
             echo "Success";
        } else { 
             print_r(error_get_last());
             echo "Fail";

为什么这封电子邮件不会发送?

$approved_id = $_POST['id'];
$approved_firstname = $_POST['firstname'];
$approved_lastname = $_POST['lastname'];
$approved_username = $_POST['username'];
$approved_email = $_POST['email'];
$change_group = $_POST['update_group'];
$email_stmt = $con->prepare("SELECT * FROM users WHERE id=?");
if ( !$email_stmt || $con->error ) {
 // Check Errors for prepare
    die('User email prepare() failed: ' . htmlspecialchars($con->error));
}
if(!$email_stmt->bind_param('ii', $change_group, $approved_id)) {
// Check errors for binding parameters
    die('User email bind_param() failed: ' . htmlspecialchars($stmt->error));
}
if(!$email_stmt->execute()) {
    die('User email execute() failed: ' . htmlspecialchars($stmt->error));

        $row = mysqli_fetch_assoc($$email_stmt);
        $pending_id = $_POST['id'];
        $group_firstname = $row['firstname'];
        $group_lastname = $row['lastname'];
        $group_username = $row['username'];
        $group_email = $row['email'];
        $group_email = $row['group'];

        $to = $approved_email;
        $subject = 'There is a new user request to join';
        $message = '
        <html>
        <head>
            <title>NewUser Request</title>
        </head>
        <body>
            <p>Hi '.$approved_firstname.',</p><br>
            <p>Your Account has been accepted. You have been added to the group. To sign in, click this link
            http://example.com . </p><br>
            <p>Thank you,</p>
            <p>Administration</p>
        </body>
        </html>
        ';

        $from = "user-requests@example.com";
        $Bcc = "user-requests-confirm@example.com";

        // To send HTML mail, the Content-type header must be set
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

        // Additional headers
        //$headers .= 'To: ' .$to;//. "\r\n";
        $headers .= 'From: ' .$from. "\r\n";
        $headers .= 'Bcc: '.$Bcc. "\r\n"; 

        // Send the email
        //mail($to,$subject,$message,$headers);
        if(mail($to,$subject,$message,$headers)){
             echo "Success";
        } else { 
             print_r(error_get_last());
             echo "Fail";
        }

0 个答案:

没有答案