PHP变量和样式

时间:2013-08-20 01:21:13

标签: php html-email

我在这里有一些代码,我试图用css设置$ first的PHP变量,但显然是不对的,因此我在这里的原因。

我最终希望设置整个邮件的样式并包含徽标和/或背景颜色,以便在发送此电子邮件时它是“html电子邮件”,但我对PHP一无所知,我想我正在学习一点一滴。

这是我的代码:------->

$user = "$email";
$usersubject = "Thank you for subscribing";
$userheaders = "From: subscriptions@3elementsreview.com\n";
$userheaders .= "Content-type: text/html\r\n";
$usermessage = "Welcome <span style='color:#ff6000; font-size:1.25em; font-    weight:bold;>$first</span>,

We're glad you've decided to subscribe to our email list!

There's a lot of great things happening at 3Elements that we can't wait to show you.

So stay tuned for notifications about submission periods, issue release dates, contests, and other news. Also, be sure to like us on Facebook and follow us on Twitter!

Sincerely,

The 3Elements Team


www.3ElementsReview.com
Facebook.com/3elementsreview
@3ElementsReview";

mail($user,$usersubject,$usermessage,$userheaders);

3 个答案:

答案 0 :(得分:0)

尝试对HTML属性使用双引号并连接$ first变量,如下所示:

$user = "$email";
$usersubject = "Thank you for subscribing";
$userheaders = "From: subscriptions@3elementsreview.com\n";
$userheaders .= "Content-type: text/html\r\n";
$usermessage = "Welcome <span style=\"color:#ff6000; font-size:1.25em; font-weight:bold;\">".$first."</span>,

We're glad you've decided to subscribe to our email list!

There's a lot of great things happening at 3Elements that we can't wait to show you.

So stay tuned for notifications about submission periods, issue release dates, contests, and other news. Also, be sure to like us on Facebook and follow us on Twitter!

Sincerely,

The 3Elements Team


www.3ElementsReview.com
Facebook.com/3elementsreview
@3ElementsReview";

mail($user,$usersubject,$usermessage,$userheaders);

答案 1 :(得分:0)

我可能会先改变

<span style='color:#ff6000; font-size:1.25em; font-    weight:bold;>

<span style='color:#ff6000; font-size:1.25em; font-weight:bold;'>

我还建议HEREDOC用于大量文本,例如

$usermessage <<<EOD

Welcome <span style="color:#ff6000; font-size:1.25em; font-weight:bold;">$first</span>,

We're glad you've decided to subscribe to our email list!

There's a lot of great things happening at 3Elements that we can't wait to show you.

So stay tuned for notifications about submission periods, issue release dates, contests, and other news. Also, be sure to like us on Facebook and follow us on Twitter!

Sincerely,

The 3Elements Team


www.3ElementsReview.com
Facebook.com/3elementsreview
@3ElementsReview
EOD;

答案 2 :(得分:0)

你可能错过了html或body标签?我发布了一个当前正在运行的我的版本。你可以修改它。请注意gmail,yahoo等不同的邮件服务器检测不同的代码格式。在某处有一个很好的比较

  $mail_body = '
    <html>
    <body>
    <p><img style="vertical-align: top;" src="http://www.chenlikonlinestore.com/css/images/logo.png" alt="logo" width="238" height="41" /></p>
    <p><a class="right" title="ChenLikPharmacy Sdn Bhd" href="http://www.facebook.com/ChenLikPharmacy" target="_blank"><img src="http://ctrlq.org/html-mail/img/facebook.png" alt="Facebook" width="25" height="25" /></a></p>
    <h3>Newsletter</h3>
    <p>Hello ' . $name . ',</p>
    <p><a href="http://www.chenlikonlinestore.com/promotions.php">Click here and check out our latest promotion!</a></p>
    <p>~Philip @ ChenLik Pharmacy Sdn. Bhd.</p>
    <hr />
    <p>This is computer generated newsletter, please do not reply to this email. <a href="http://www.chenlikonlinestore.com/php_codes/optout.php?e='.$email.'">Click here</a> to unsubscribe</p>
    </body>
    </html>';