【问题标题】:Random Spaces in PHP Variable [closed]PHP变量中的随机空间[关闭]
【发布时间】:2015-11-02 08:34:16
【问题描述】:

当用户提交表单时,我正在使用以下 PHP 代码发送电子邮件。

$to = 'mail@example.com';
$subject = 'Thank you for your mail ' . $mailRefrence . ' - www.example.com';
$headers = "From: " . 'info@example.com' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

$message = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv='Content-Type' content='text/html;.......";
$message .= $mailReference;

mail($to, $subject, $message, $headers);

请注意,$message-variable 中的 HTML 代码要长得多,我刚刚删除了它,因为这里粘贴的时间太长了。

但是,当邮件发送给用户时,文本中有随机空格。有时空格会出现在文本中,有时会出现在代码中,这往往会破坏邮件的整体设计。

有谁知道为什么会发生这种情况以及如何解决它?

编辑:

我正在为 HTML 邮件使用 ZURB 模板。

源代码在这里:http://zurb.com/playground/projects/responsive-email-templates/basic.html

【问题讨论】:

  • 把“间隔”的结果。否则我们看不到会发生什么
  • 您是否在 html 中使用输入和制表符来提高可读性?
  • 尝试使用 trim() 函数。 trim($message),然后使用它。邮件($to, $subject, $message, $headers);
  • 如果随机间距出现在 HTML 邮件中,那么 HTML 邮件可能是最相关的。
  • Trim() 函数不起作用,抱歉。

标签: php html css email html-email


【解决方案1】:
$message = <<< EOD

your message content will be here ...it will show as you send either it is space or new line doesn't effect.

EOD;

【讨论】:

  • 这在 PHP 中称为heredoc,是为变量分配多行预格式化文本的正确方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-26
  • 2014-10-31
  • 1970-01-01
  • 1970-01-01
  • 2013-05-09
相关资源
最近更新 更多