首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带PHPMailer的Ckeditor -空正文消息

带PHPMailer的Ckeditor -空正文消息
EN

Stack Overflow用户
提问于 2022-10-09 20:24:55
回答 1查看 34关注 0票数 0

因此,我将PHPMailer添加到我的网站上,并设法使其正常工作。然而,在添加Ckeditor以替换"message / body“字段后,电子邮件不会在没有任何内容的情况下发送。

--这是表单位于的索引文件

代码语言:javascript
复制
<?php
include '../../../../config.php';

$connect = new PDO("mysql:host=$servername;dbname=$dbname", "$username", "$password");
$query = "SELECT * FROM uni_clients ORDER BY clients_id";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
?>

<!DOCTYPE html>
<html>
 <head>
     
<!-- this is for the button to disable it if checkboxes are unchecked -->
<script>
function toggle(source) {
checkboxes = document.getElementsByName('single_select');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
  }
}
 </script>
    
 <script>
function terms_changed(termsCheckBox){
    //If the checkbox has been checked
    if(termsCheckBox.checked){
        //Set the disabled property to FALSE and enable the button.
        document.getElementById("bulk_email").disabled = false;
    } else{
        //Otherwise, disable the submit button.
        document.getElementById("bulk_email").disabled = true;
    }
}
</script>
         


<style>
.error {color: #FF0000;}
</style>


  <title>Send Bulk Email </title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="include/modules/massmail/styles.css">
 </head>
 
 
 <body>
      
  <br />
  <div class="container">
   <h3 align="center"><strong>Choose users from the list</strong></h3>
   
   <br />
   

<!-- Creating the table that displays the users in the database and their details -->
   <div class="class="table-wrapper>
    <table class="fl-table">
     <tr>
      <th>Customer's Name</th>
      <th>Email</th>
      <th>Select</th>
      <th>Action</th>
     </tr>
     
     
     <?php
     $count = 0;
     foreach($result as $row)
     {
      $count++;
      echo '
      <tr>
       <td>'.$row["clients_name"]." " .$row["clients_surname"].'</td>
       <td>'.$row["clients_email"].'</td>
       <td>
        <input type="checkbox" name="single_select" id="checkbox" onclick="terms_changed(this)" class="single_select" data-email="'.$row["clients_email"].'" data-name="'.$row["clients_name"].'" />
       </td>
       <td><button type="button" name="email_button" class="btn btn-info btn-xs email_button" id="'.$count.'" data-email="'.$row["clients_email"].'" data-name="'.$row["clients_name"].'" data-action="single">Send Single</button></td>
      </tr>
      ';
     }
     ?>
    
     </td>
    </table>
   </div>
   <input  type="checkbox"  onClick="toggle(this),terms_changed(this)" id="checkbox" /> Choose All Users <br/><br>
  </div>
  
  

  <div class="container">
      
   <br />



   <div style="text-align:center">
       <h3> <strong>Email Subject</strong></h3>
       <input type="text" id="subject" placeholder="subject" value="" /> <br><br>
       
<!-- This is where the issue starts after Ckeditor -->
       <h3><strong> Email Body </strong></h3>
       <textarea id="message" name="message" rows="5" cols="5" >
</textarea>

<script src="../../../../admin-panel/files/js/ckeditor/ckeditor.js"></script>
<script>CKEDITOR.replace("message")</script>
              
     
    <button type="button" style="background:orange;width:25%" id="bulk_email"  name="bulk_email" class="btn btn-info email_button" id="bulk_email" data-action="bulk"disabled>Send Emails</button>
  
   </div>
  </div>
  
  
  
 </body>
</html>

<script>
$(document).ready(function(){
 $('.email_button').click(function(){
  $(this).attr('disabled', 'disabled');
  var id = $(this).attr("id");
  var action = $(this).data("action");
  var email_data = [];
  if(action == 'single')
  {
   email_data.push({
    email: $(this).data("email"),
    name: $(this).data("name"),
    subject: $(subject).val(),
    message: $(message).val() 
   });
  }
  else
  {
   $('.single_select').each(function(){
    if($(this). prop("checked") == true)
    {
     email_data.push({
      email: $(this).data("email"),
      name: $(this).data('name'),
      subject: $(subject).val(),
    message: $(message).val()
     });
    }
   });
  }
  
  $.ajax({
   url:"include/modules/massmail/send_mail.php",
   method:"POST",
   data:{email_data:email_data},
   beforeSend:function(){
    $('#'+id).html('Sending...');
    $('#'+id).addClass('btn-danger');
   },
   success:function(data){
    if(data = 'ok')
    {
     $('#'+id).text('Success');
     $('#'+id).removeClass('btn-danger');
     $('#'+id).removeClass('btn-info');
     $('#'+id).addClass('btn-success');
    }
    else
    {
     $('#'+id).text(data);
    }
    $('#'+id).attr('disabled', false);
   }
   
  });
 });
});
</script>

这是send_mail.php页面(用于phpmailer) :

代码语言:javascript
复制
<?
if(isset($_POST['email_data']))
{
include  '../../../../config.php';
require 'PHPMailer/PHPMailerAutoload.php';
 $output = '';
 foreach($_POST['email_data'] as $row)
 {
  $mail = new PHPMailer;
  $mail->IsSMTP();        //Sets Mailer to send message using SMTP
  $mail->Host = $mailHost;  //Sets the SMTP hosts of your Email hosting, this for Godaddy
  $mail->Port = $mailPort;        //Sets the default SMTP server port
  $mail->SMTPAuth = $mailSMTPAuth;       //Sets SMTP authentication. Utilizes the Username and Password variables
  $mail->Username = $mailUsername;     //Sets SMTP username
  $mail->Password = $mailPassword;     //Sets SMTP password
  $mail->SMTPSecure = $mailSMTPSecure;       //Sets connection prefix. Options are "", "ssl" or "tls"
  $mail->From = $mailFrom;   //Sets the From email address for the message
  $mail->FromName = $mailFromName;     //Sets the From name of the message
  $mail->AddAddress($row["email"], $row["name"]); //Adds a "To" address
  $mail->WordWrap = 50;       //Sets word wrapping on the body of the message to a given number of characters
  $mail->IsHTML(true);       //Sets message type to HTML
  $mail->Subject = $row["subject"]; 
  $mail->Body = $row["message"];

  $mail->AltBody = '';

  $result = $mail->Send();      //Send an Email. Return true on success or false on error

  if($result["code"] == '400')
  {
   $output .= html_entity_decode($result['full_error']);
  }

 }
 if($output == '')
 {
  echo 'ok';
 }
 else
 {
  echo $output;
 }
}

?>

我很感激你这么做了,我知道答案可能比我想的要容易,我还在学习。

我现在和你分享两张图片,给你看我收到的截图-页页面和电子邮件。

空电子邮件/正文

EN

回答 1

Stack Overflow用户

发布于 2022-10-09 22:10:36

可能是这行$mail->AltBody = '';

删除$mail->AltBody,或

设置一个句子:$mail->AltBody = "To get this email correctly, use an email viewer with HTML support"

我参加了考试

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74008125

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档