邮件传递失败:正在向发件人返回邮件。在PHP中

时间:2019-07-17 12:50:14

标签: php phpmailer

邮件传递失败:正在向发件人返回邮件。

我需要这种类型的电子邮件状态,请帮助我// Instantiation and passing true`启用例外     $ mail = new PHPMailer(true);     // $ mail-> MailerDebug = false;

try {
    //Server settings
    $mail->SMTPDebug = 0;                                       // Enable verbose debug output
    $mail->isSMTP();                                            // Set mailer to use SMTP
    $mail->Host       = 'server.mail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = 'xyz@abc.com';                     // SMTP username
    $mail->Password   = '*******';                               // SMTP password
    $mail->SMTPSecure = 'tls';                                  // Enable TLS encryption, `ssl` also accepted
    $mail->Port       = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom($fromemail, $fromname);
    foreach ($toarray as $key => $value) {
            $mail->addAddress($value);
    }
        // Add a recipient
   // $mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo($replyto, '');
    foreach ($bccarray as $key => $value) {
        $mail->addBCC($value);
    }
    foreach ($ccarray as $key => $value) {
        $mail->addCC($value);
    }


    // Attachments
    if(empty($filearray) == false)
while ($filesubarray = current($filearray))
{
    if(empty($filesubarray) == false)
    {
        $file = $filesubarray[0]; //physical location of the file
        //$position = $filesubarray[1]; //inline or attachment.
        $id = $filesubarray[2]; //unique id for that email considering all the attachments.
        $mail->AddEmbeddedImage($_SERVER['DOCUMENT_ROOT'].'/'.$file,$id);
        //$mail->AddAttachment($_SERVER['DOCUMENT_ROOT'].'/project/imax/'.$file);
    }
    next($filearray);
}

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = $subject;
    $mail->Body    = $html;
    $mail->AltBody = $text;

    $state = $mail->send();
    return array(
            'status' => true,
            'message' => $_->_('__MAIL_WAS_SEND__')
        );
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}`

这是我针对php mailer的代码,因为我们将获得已发送或未发送状态的邮件,但我需要传递状态

0 个答案:

没有答案