PHP mail function 'from' address

后端 未结 3 1232
庸人自扰
庸人自扰 2020-11-29 09:38

I\'m not even sure this is possible, however what I\'m trying to do is as follows. I have an HTML form that generates and email using a PHP script. What I want

相关标签:
3条回答
  • 2020-11-29 09:46

    For a php mail script I have used this for contact forms:

    $from = $_POST["from"];  //posted from the form.
    
    mail("me@myname.com", $subject, $message, "From:" . $from);
    

    I have not used a sendmail_from in my php before, only a simple variable.

    I hope this helps!

    0 讨论(0)
  • 2020-11-29 09:47

    See this page on the same site (example 2): http://www.w3schools.com/php/func_mail_mail.asp

    You will have to set the headers of the message to include the From and other stuff like CC or BCC:

    <?php
    $to = "somebody@example.com";
    $subject = "My subject";
    $txt = "Hello world!";
    $headers = "From: webmaster@example.com\r\n";
    
    mail($to,$subject,$txt,$headers);
    ?>
    

    Note that you have to separate the headers with a newline sequence "\r\n".

    0 讨论(0)
  • 2020-11-29 09:58

    Any reason you cant do it in the email headers?

    $to      = 'hello@hello.com';
    $subject = 'my subject';
    $message = 'hello';
    $headers = 'From: '.$email_from_form. "\r\n";
    
    mail($to, $subject, $message, $headers);
    
    0 讨论(0)
提交回复
热议问题