duanhong8839 2019-04-10 14:55
浏览 239
已采纳

如何发送主题有特殊字符的电子邮件?

when I send the email, if the subject says "Ç", it shows "?".

already tried to implement:

-charset="ascii";

-charset=UTF-8;

-$mail->$subject = "=?ISO-8859-1?Q?".imap_8bit("äöüßÄÖÜ sollte hier gehen")."?=";

-$mail->$subject = '=?UTF-8?B?'.base64_encode(utf8_encode("çççç")).'?=';

So far I can not solve this, what else can I do? I already searched in the forum has a lot of post to talk about it but none solved my problem.

My exemple code is :

$mail = new PHPMailer();
    $mail->charset="UTF-8";
    $mail->IsSMTP();
    $mail->Host = "*.*.*.*:*";
    $mail->SMTPAuth = false;
    $mail->From = "*@*.*";
    $mail->FromName = "newjob";  
    $mail->addAddress($add1, $addnome1);
    if($add2!=""){ $mail->addAddress($add2, $addnome2);};  
    if($add3!=""){ $mail->addAddress($add3, $addnome3);};  
    $mail->ContentType = 'text/calendar; charset=utf-8';
    $mail->$subject = "=?ISO-8859-1?Q?".imap_8bit("äöüßÄÖÜ")."?=";
    // $mail->$subject = '=?UTF-8?B?'.base64_encode(utf8_encode("çççç")).'?=';
    
    $ical = "BEGIN:VCALENDAR
";
    $ical .= "VERSION:2.0
";
    $ical .= "PRODID:-sigma.eda.pt
";
    $ical .= "METHOD:PUBLISH
";
    $ical .= "BEGIN:VEVENT
";
    $ical .= "ORGANIZER;SENT-BY=\"MAILTO:$add1
";
    $ical .= "ATTENDEE;CN=$add1;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=false:mailto:$add1
";
    $ical .= "UID:".strtoupper(md5($event_id))."-sigma.eda.pt
";
    $ical .= "SEQUENCE:".$sequence."
";
    $ical .= "STATUS:".$status."
";
    $ical .= "DTSTAMPTZID=Europe/azores:".date('Ymd').'T'.date('His')."
";
    $ical .= "DTSTART:".$start."T".$start_time."
";
    $ical .= "DTEND:".$end."T".$end_time."
";
    $ical .= "LOCATION:".$venue."
";
    $ical .= "SUMMARY:".$summary."
";
    $ical .= "DESCRIPTION:".$descr."
";
    $ical .= "RRULE:FREQ=MONTHLY;INTERVAL=".$rotina.";COUNT=".$repete.";
";
    $ical .= "BEGIN:VALARM
";
    $ical .= "TRIGGER:-PT15M
";
    $ical .= "ACTION:DISPLAY
";
    $ical .= "DESCRIPTION:Reminder
";
    $ical .= "END:VALARM
";
    $ical .= "END:VEVENT
";
    $ical .= "END:VCALENDAR
";
    $mail->Body = $ical;
      try {
       if ( !$mail->Send() ) {
        //  $error = "Unable to send the email <br />";
        //  throw new phpmailerAppException($error);
       } else {
        //  echo 'Message has been sent<br /><br />';
       }
     } catch (phpmailerAppException $e) {
      //  $errorMsg[] = $e->errorMessage();
     }

EDIT image error from test:

here

</div>
  • 写回答

1条回答 默认 最新

  • duan0708676887 2019-04-10 17:25
    关注

    PHP has case sensitive class properties, which means that when a property has a name CharSet, it has to be defined like this and not in lowercase $mail->charset. This also aplies to $mail->$subject and $mail->addAddress, addAddress case is like this. Here is an example with greek text that's working without any text conversion:

    EDIT

    I've tested this code above and it's working:

    $email = 'some@email.com';
    $message =  'Όνομα: <br/>'.
        'eMail: <br/>'.
        'Τηλέφωνο: <br/>'.
        '(Ç, ç, äöüßÄÖÜ sollte hier gehen, açores)';
    
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    
    $mail = new PHPMailer(true);
    
    try {
        $mail->isMail();
        $mail->addAddress($email);
        $mail->setFrom('test@email.com', 'Mailer');
        $mail->CharSet = PHPMailer::CHARSET_UTF8;
        $mail->Subject = "[ΣΥΜΜΕΤΟΧΗ] Νέα φόρμα δήλωσης συμμετοχής (Ç, ç, äöüßÄÖÜ sollte hier gehen, açores)";
    
        $mail->msgHTML($message);
        $mail->send();
        echo 'Message has been sent';
    } catch(Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }
    

    And here is the screenshot of the received email:

    Result email screenshot

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来