Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHPMailer发送纯文本电子邮件_Php_Email_Formatting_Phpmailer_Plaintext - Fatal编程技术网

使用PHPMailer发送纯文本电子邮件

使用PHPMailer发送纯文本电子邮件,php,email,formatting,phpmailer,plaintext,Php,Email,Formatting,Phpmailer,Plaintext,我使用PHPMailer发送纯文本电子邮件时遇到问题 我从文本文件中读取文本,并通过PHPMailer将其发送给邮件收件人 当收件人收到实际的电子邮件时,邮件的格式与文本文件中的格式不同,所有内容都在一行中,我发送的电子邮件中没有新的行和选项卡。文字环绕完全关闭 代码: 您正在将$mail->MsgHTML()设置为纯文本消息,并且由于在HTML中忽略空白格式,因此您将获得一个内联文本 我已经有一段时间没有使用PHPMailer了,但从内存中可以尝试: $mail->Body = file

我使用PHPMailer发送纯文本电子邮件时遇到问题

我从文本文件中读取文本,并通过PHPMailer将其发送给邮件收件人

当收件人收到实际的电子邮件时,邮件的格式与文本文件中的格式不同,所有内容都在一行中,我发送的电子邮件中没有新的行和选项卡。文字环绕完全关闭

代码:


您正在将
$mail->MsgHTML()
设置为纯文本消息,并且由于在HTML中忽略空白格式,因此您将获得一个内联文本

我已经有一段时间没有使用PHPMailer了,但从内存中可以尝试:

$mail->Body = file_get_contents($newFile); 

请尝试以下代码,这些代码工作正常:

        try {
            $mail->AddAddress('jitpal@domain.com', 'Jit Pal');
            $mail->SetFrom('testuser@domain.com', 'Test User');
            $mail->Subject = "All machine's tests.";
            $mail->Body = "All machine's tests working fine.";
            $mail->Send();
            echo "<br/>Message sent successfully...<br/><br/>\n";
        } catch (phpmailerException $e) {
            echo $e->errorMessage();
        } catch (Exception $e) {
            echo $e->getMessage();
        }
试试看{
$mail->AddAddress('jitpal@domain.com“,”Jit Pal“);
$mail->SetFrom('testuser@domain.com“,”测试用户“);
$mail->Subject=“所有机器的测试。”;
$mail->Body=“所有机器的测试工作正常。”;
$mail->Send();
echo“
消息已成功发送…

\n”; }捕获(phpmailerException$e){ echo$e->errorMessage(); }捕获(例外$e){ echo$e->getMessage(); }
这是一个域注册文件whois.co.za,但问题已经解决。Thx JAMES您可以将
if($mail->Send())
部分简化为
return$mail->Send()+1用于解释要排除的行以及要包含的行,以仅触发文本。
    $mail->ContentType = 'text/plain'; 
    $mail->IsHTML(false);
    $address = "test@test.com";
    $mail->AddAddress($address, "John Doe");

    $mail->SetFrom(EMAIL_TEST_FROM);

    $mail->AddReplyTo(EMAIL_TEST_REPLY);



    $mail->Subject = $action." REGISTRATION ".$formName.$tld;
    $mail->From = EMAIL_TEST;  

    // Very important: don't have lines for MsgHTML and AltBody 
    $mail->Body = file_get_contents($mailBodyTextFile);  
    // $mail->Body = $_POST["msg"];  //If using web mail form, use this line instead.


    if($mail->Send()){
        return true;
    }
        try {
            $mail->AddAddress('jitpal@domain.com', 'Jit Pal');
            $mail->SetFrom('testuser@domain.com', 'Test User');
            $mail->Subject = "All machine's tests.";
            $mail->Body = "All machine's tests working fine.";
            $mail->Send();
            echo "<br/>Message sent successfully...<br/><br/>\n";
        } catch (phpmailerException $e) {
            echo $e->errorMessage();
        } catch (Exception $e) {
            echo $e->getMessage();
        }