2015-02-06 45 views
-5

简而言之,我试图在用户使用php提交联系表单时向用户写入消息。问题是,我试图通过添加样式元素(如粗体)来设置消息的样式,并用<br>间隔某些行。它似乎适用。在php中添加html属性

以下是代码。

$message = "Welcome". $full_name . "to Company!" . "<br>". "<br>". "<b>". " Company is 
    the mailbox for the 21st century that evolves per your need. " . "</b>". "<br>". "<br>". " 
    Letting you interact with you mail by viewing and deciding what to do with it as it is received at a 
    Company location throughout North America. ". "<b>". "Please use the below information to send a mail/package to your selected address:". "</b>". "<br>". $full_name. "<br>". $address. "<br>". "To login to your dashboard, please visit the following link"."<br>". "<a href=''http://company.com/userinterfaceSelect.php'>Your Dashboard</a>" ; 

其中有<br>, <b>,和一个链接,其中似乎没有适用。

更新;

<?php 
if(isset($_POST['submit'])){ 
    $to = $_POST['email'];// this is your Email address 
    $from = "[email protected]"; // this is the sender's Email address 
    $full_name = $_POST['fullName']; 
     $address = $_POST['address']; 

    $subject = "Welcome to company"; 
    $subject2 = "Copy: New Registration"; 
    $message2 = "New User". "<br>" .$full_name . "\n\n" ; 
    $message = "Welcome". $full_name . "to company!" . "<br>". "<br>". "<b>". " company is 
    the mailbox for the 21st century that evolves per your need. " . "</b>". "<br>". "<br>". " 
    Letting you interact with you mail by viewing and deciding what to do with it as it is received at a 
    Company location throughout North America. ". "<b>". "Please use the below information to send a mail/package to your selected address:". "</b>". "<br>". $full_name. "<br>". $address. "<br>". "To login to your dashboard, please visit the following link"."<br>". "<a href=''http://company/userinterfaceSelect.php'>Your Dashboard</a>" ; 

    $headers = "From:" . $from; 
    $headers2 = "From:" . $to; 
    mail($to,$subject,$message,$headers); 
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender 
echo "Your mail has been sent successfuly ! Thank you for your feedback"; 
    // You can also use header('Location: thank_you.php'); to redirect to another page. 
    } 
?> 
+2

输出怎么样?在给用户的电子邮件中?在页面上?定义'似乎适用'。等等 – Utkanos 2015-02-06 14:15:15

+3

'在php'中''文体元素'''它确实似乎适用.' ...(͡°͜ʖ͡°) – 2015-02-06 14:16:19

+0

输出到用户的电子邮件 – Jon220 2015-02-06 14:19:40

回答

1

你非常接近它的工作。

您需要添加一个标题,表示内容是HTML:

Content-Type: text/html; charset=ISO-8859-1 

例如,你的头可能形成如下:

$headers = "From: [email protected]\r\n"; 
$headers .= "Reply-To: [email protected]\r\n"; 
$headers .= "CC: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

参见下面的参考资料细节。

参考文献:

http://php.net/manual/en/function.mail.php

http://css-tricks.com/sending-nice-html-email-with-php/

+0

谢谢,但那么我将如何风格的身体? – Jon220 2015-02-06 14:41:24

+1

这个答案是正确的,但我的建议是将HTML放在外部文件中,并在其中放置特定格式的变量(例如'## fullname ##')。然后,当您需要发送邮件时,将该文件加载到一个字符串中并用该值替换变量。我认为它更清洁,这可以让你集中在某处的HTML模板。如果需要的话,它也可以减轻翻译过程。 – 2015-02-06 14:41:41

+0

我同意,OP应该使用模板方法甚至某种类型的PEAR包。正如他所说,他正在开始。 – 2015-02-06 15:09:38