更改电子邮件地址 PHP 联系表

Change e-mail address PHP contact form

我目前正在编写我的联系表脚本,每次填写联系表时,我都能完美地收到邮件,没有任何问题。电子邮件看起来像这样

发件人:noreply@domain.tld 主题:联系表格提交。我想将 noreply@domain.tld 更改为我的公司名称...这样每次我收到邮件时都不会看到显示的电子邮件地址,而是我会看到我的公司名称。当然,回复功能必须保持活跃。有人可以帮我吗?

    <?php

// Check if the form has been posted
if (isset($_POST['submit'])) {
    // The email address the email will be sent to
    $to = "xx@domain.pl";
    // The email subject
    $subject = "Contact Form Submission";
    // Set the from and reply-to address for the email
    $headers = "From: no-reply@xxx.pl\r\n"
             . "X-Mailer: PHP/" . phpversion();
    // Build the body of the email
    $mailbody = "The contact form has been filled out.\n\n"
              . "Name: " . $_POST['naam'] . "\n"
              . "Email: " . $_POST['email'] . "\n"
              . "Message:\n" . $_POST['vraag'];
    // Send the email
    mail($to, $subject, $mailbody, $headers);
    // Go to the thank you page
    header("location: thankyou.html");
    exit;

}

邮箱地址格式应符合RFC 2822标准:

Normally, a mailbox is comprised of two parts: (1) an optional display name that indicates the name of the recipient (which could be a person or a system) that could be displayed to the user of a mail application, and (2) an addr-spec address enclosed in angle brackets ("<" and ">"). There is also an alternate simple form of a mailbox where the addr-spec address appears alone, without the recipient's name or the angle brackets.

所以,你应该这样写"Company name <name@company.tld>"。替换此行:

$headers = "From: no-reply@domain.tld\r\n"

与:

$headers = "From: Company name <no-reply@domain.tld> \r\n"