简体   繁体   中英

Change e-mail address PHP contact form

I am currently working on my contact form script and everytime when I fill in my contact form I am receiving the mail perfectly with no problems at all. The e-mail looks like this

From: noreply@domain.tld and subject: Contact Form Submission. I would like to change noreply@domain.tld into My company name... so that everytime when I'm receiving the mail that I won't see the email address displaying but instead of that I will see my company name. Ofcourse, reply-to function has to stay active. Can someone help me out?

    <?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;

}

The format of the e-mail adress should comply with the RFC 2822 standard:

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.

So, you should write like "Company name <name@company.tld>" . Replace this line:

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

with:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM