【问题标题】:PHP E-mail form - Define senderPHP 电子邮件表单 - 定义发件人
【发布时间】:2018-03-19 22:48:45
【问题描述】:

我正在尝试创建一个 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ê;

有可能吗?

谢谢你, 维托

【问题讨论】:

    标签: php html css email


    【解决方案1】:

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

    $headers = "From:" . $from . "\r\n";
    
    mail($destinationemail, $subject, $emailcontent, $headers) or die("Error!");
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多