简体   繁体   English

如何格式化php电子邮件

[英]how to format php email

I will make it really simple. 我会让它变得非常简单。 I want to send an email by php. 我想通过php发送电子邮件。 now here is code. 现在这里是代码。

$line = '\n';
$a = "Customer Phone: ";
$b = "Customer Last Name: ";
$message = $a.$number.$line.$b.$LastName;       

$to = "forgotten_tarek@yahoo.com";
$subject = "Umrah Booking";
$from = $mailer;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);

here is the output: 这是输出:

Customer Phone: 0712345678\nCustomer Last Name: Showkot

and the email is showing no sender. 并且电子邮件显示没有发件人。 It says nobody . nobody说。

I want the email to be look like: 我希望电子邮件看起来像:

Customer Phone: 0712345678
Customer Last Name: Showkot

and I also want to show that the email is from example@example.com 我还想表明该电子邮件来自example@example.com

1) Change '\\n' to "\\n" . 1)将'\\n'更改为"\\n" Special characters (such as \\n ) are interpreted only in double-quoted strings . 特殊字符(例如\\n )仅在双引号字符串中解释。

2) Try to change "From:" to "From: " . 2)尝试将"From:"更改为"From: " Or, perhaps, variable $from has no value. 或者,变量$from也许没有价值。

You can use a html mail also., in that you can send a mail which is actually formatted using html.. this is very simple and yu can almost use all tags which yu use to format content in html and even css can be added..!! 你也可以使用html邮件,因为你可以发送一个实际使用html格式化的邮件..这很简单,yu几乎可以使用yu用于格式化html内容的所有标签,甚至可以添加css。 。! you need to add headers to send html mail. 你需要添加标题来发送HTML邮件。

here is a example..! 这是一个例子..!

$to = "sended@test.com";
$subject = "Test mail";
$a = "Customer Phone: ";
$b = "Customer Last Name: ";
$message = $a.$number.$line.$b.$LastName;  
$message="
<html>
<body>
  <h1>$a</h1>: $number <br> <h1>$b</h1>: $LastName<br>
</body>
</html>";

$from = "tester@test.com";
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";

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

try this too., it will work..! 试试这个。,它会工作..! :) :)

$line = "\n";
$a = "Customer Phone: ";
$b = "Customer Last Name: ";
$message = $a.$number.$line.$b.$LastName;

$to = "forgotten_tarek@yahoo.com";
$subject = "Umrah Booking";
$from = $mailer;
$headers = "From: " . $from. "\r\n".
'Reply-To: '. $from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to,$subject,$message,$headers);

You can enter html in the message tag for example: 您可以在消息标记中输入html,例如:

$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';

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

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