简体   繁体   English

尝试使用php邮件功能对齐文本发送邮件

[英]Trying to align text sending mail using php mail function

i am sending some HTML text using the PHP mail function. 我正在使用PHP邮件功能发送一些HTML文本。

So the text is 所以文字是

$msg='<h1>This is the mail text i want to center</h1>';

then i am using the mail function like: 然后我正在使用邮件功能,如:

mail($recipient,$subject,$msg,$mailheaders);

I receive the email but all text is left aligned. 我收到了电子邮件,但所有文本均保持对齐。 I tried to use center tags 我尝试使用中心标签

$msg='<center><h1>This is the mail text i want to center</h1></center>';

but the mail never goes (it is not allowed?) 但邮件永不发送(不允许吗?)

also tried to use style attribute 也尝试使用样式属性

$msg='<h1 style="text-align:center;">This is the mail text i want to center</h1>';

but again no luck. 但同样没有运气。 Any ideas welcome 任何想法欢迎

it's always hard to send a good mail with a nice design. 总是很难用一个好的设计发送一封好邮件。

One (old) way is to use table but it's not really nice. 一种(旧的)方法是使用表,但这并不是很好。 Now you can use some good third party libs like phpmailer or others. 现在,您可以使用一些不错的第三方库,例如phpmailer或其他。 You will need to apply inline css since providers don't supports external CSS. 由于提供者不支持外部CSS,因此您将需要应用内联CSS。

check this article https://www.formget.com/php-send-html-email-template/ 检查本文https://www.formget.com/php-send-html-email-template/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM