How do I set the name of an email sender via PHP

前端 未结 6 950
自闭症患者
自闭症患者 2020-12-30 03:00

So I want the from field when an email is opened to be something like

\"Jack Sparrow Via somesite\" as opposed to an explicit email address

相关标签:
6条回答
  • 2020-12-30 03:29

    If you use PHP Mailer from GitHub, then you do it by:

    $mail->SetFrom("info@mibckerala.org", "MIBC");
    
    0 讨论(0)
  • 2020-12-30 03:30

    just use like this

    $headers .= 'From: [Name of the person]'.'<'. $this->from .'>'. "\n";
    

    in Header Section.

    0 讨论(0)
  • 2020-12-30 03:35

    You can accomplish this by using basic headers.

    <?php
    $to      = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: Jack Sparrow <jsparrow@blackpearl.com>' . PHP_EOL .
        'Reply-To: Jack Sparrow <jsparrow@blackpearl.com>' . PHP_EOL .
        'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);
    ?>
    
    0 讨论(0)
  • 2020-12-30 03:35

    I am not sure exactly what you mean, but as you can see on PHP.net mail function.

    To add the name to the from section you need to send this in the headers. From:Name<email@example.com>

    0 讨论(0)
  • 2020-12-30 03:37

    You have to set your headers:

    $to = "Someone@email.com";
    $header = "FROM: Jack Sparrow <some@site.com>\r\n";
    $message = "Your message here.";
    $subject = "Your subject";
    
    mail($to,$subject,$message,$header) or die();
    
    0 讨论(0)
  • 2020-12-30 03:38
    $to = "Someone@email.com";
    $message = "Your message here.";
    $subject = "Your subject";
    
    mail($to,$subject,$message,$header, '-f some@site.com -F "Jack Sparrow"') or die();
    

    Just add the -f parameter to provide the sender's email and -F parameter to provide the sender's name to the mail(), all as a string.

    Note: double quotes around "Jack Sparrow"

    Assuming that you are using sendmail on a Linux machine:

    You can find more detailed information by typing "man sendmail" in your shell.

    0 讨论(0)
提交回复
热议问题