2017-10-08 88 views
0

我试图创建一个HTML表单,这将最终使用folling PHP代码发送电子邮件:PHP电子邮件形式 - 定义发件人

<?php 

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

$destinationemail = "[email protected]"; 

$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的普通电子邮件中发出的邮件。

[email protected] 
<[email protected]> 
dom 08/10/2017, 18:40 
Você; 

我想它要接收这样的事:

[email protected] 
<[email protected]> 
dom 08/10/2017, 18:40 
Você; 

这可能吗?

谢谢 维克托•

回答

0

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

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

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

Ref。 https://www.w3schools.com/php/func_mail_mail.asp