PHP电子邮件表单 - 定义发件人

时间:2017-10-08 18:07:36

标签: php html css email

我正在尝试创建一个HTML表单,最终将使用以下PHP代码发送电子邮件:

<?php 

$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$destinationemail = "myemail@domain.com";

$emailcontent = "Name: {$name}\n\nE-Mail: {$email}\n\nMessage: {$subject}\n{$message}";
$subject = "Contact from Domain.com";
$from = $email;

mail($destinationemail, $subject, $emailcontent) or die("Error!");
echo "Thank you $name!";

?>

问题是,每当我收到一封电子邮件时,我就会发现,好像是从我猜的Webhost通用电子邮件发送的。

htgkaylg@server776.web-hosting.net 
<htgkaylg@server776.web-hosting.net>
dom 08/10/2017, 18:40
Você;

我希望能收到这样的内容:

myemail@domain.com 
<myemail@domain.com>
dom 08/10/2017, 18:40
Você;

有可能吗?

谢谢你, 维克托•

1 个答案:

答案 0 :(得分:0)

您必须在邮件()函数中使用标题作为第4个参数。 添加此行并更改邮件如下:

$headers = "From:" . $from . "\r\n";

mail($destinationemail, $subject, $emailcontent, $headers) or die("Error!");

参考。 https://www.w3schools.com/php/func_mail_mail.asp