我正在尝试使用php实现发送电子邮件功能。它工作正常。但是当我在收件箱中打开电子邮件时,它在消息前面有很多空格。有没有办法摆脱这些空间。
我是否需要为此添加其他标头。
码
$to = $email;
$from = "email@gmail.com";
$subject = "Registration confirmation";
$msg = "message goes here";
$mail = new EMAIL();
$arr = $mail->sendEmail($to,$from,$subject,trim($msg));
感谢。
答案 0 :(得分:2)
这样做:
<?php
$msg = trim($msg);
$msg = preg_replace('/\s+/', ' ', $msg);
$arr = $mail->sendEmail($to, $from, $subject, $msg);
答案 1 :(得分:0)
试试这个:
$to = $email;
$from = "email@gmail.com";
$subject = "Registration confirmation";
$msg = "message goes here";
$mail = new EMAIL();
$arr = $mail->sendEmail($to,$from,$subject,trim(preg_replace('/\s+/',' ', $msg));
这将删除多余的空格,以及前导和尾随空格。