我会让它变得非常简单。我想通过php发送电子邮件。现在这里是代码。
$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);
这是输出:
Customer Phone: 0712345678\nCustomer Last Name: Showkot
并且电子邮件显示没有发件人。它说nobody
。
我希望电子邮件看起来像:
Customer Phone: 0712345678
Customer Last Name: Showkot
我还想表明该电子邮件来自example@example.com
答案 0 :(得分:6)
1)将'\n'
更改为"\n"
。特殊字符(例如\n
)仅在double-quoted strings中解释。
2)尝试将"From:"
更改为"From: "
。或者,变量$from
可能没有价值。
答案 1 :(得分:5)
你也可以使用html邮件。,因为你可以发送一个实际使用html格式化的邮件..这很简单,yu几乎可以使用yu用来格式化html内容的所有标签甚至css都可以加上.. !!你需要添加标题来发送HTML邮件。
这是一个例子..!
$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);
试试这个。它会起作用..! :)
答案 2 :(得分:2)
$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);
答案 3 :(得分:0)
您可以在消息标记中输入html,例如:
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';