mail() sends with the server email address

Discussion in 'PHP' started by qwikad.com, Jul 27, 2024.

  1. #1
    How do I change it to a custom email?
    ......
    mail($user_email, $subj, $msg, $noreply_email, "ISO-8859-1");

    Instead of sending it with the $noreply_email it sends it with the server email address, something like

    Thanks!
     
    Solved! View solution.
    qwikad.com, Jul 27, 2024 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,279
    Likes Received:
    1,696
    Best Answers:
    31
    Trophy Points:
    475
    #2
    I got it sorted out. It handles it through the "$headers". Something like this:

    $headers = 'From: '.$noreply_email.'';

    ......
    mail($user_email, $subj, $msg, $headers, "ISO-8859-1");
     
    qwikad.com, Jul 27, 2024 IP
    sarahk likes this.
  3. #3
    you should do that
    $user_email = "";
    $subj = "Your Subject Here";
    $subj = "Your Subject Here";
    $noreply_email = "";
    $headers = "From: " . $noreply_email . "\r\n" . "Content-Type: text/plain; charset=ISO-8859-1\r\n";
    mail($user_email, $subj, $msg, $headers);

    This will send the email with the custom email address specified in $noreply_email as the sender.
     
    Last edited: Jul 27, 2024
    zaidzahid, Jul 27, 2024 IP
    sarahk likes this.
  4. GreenHost.Cloud

    GreenHost.Cloud Active Member

    Messages:
    471
    Likes Received:
    34
    Best Answers:
    3
    Trophy Points:
    73
    #4
    To send an email from a custom address instead of the server's default address, you can modify the `mail()` function. Make sure to include the custom email in the headers. Change your code to something like:
    $headers = "From: Your Name <customemail@yourdomain.com>\r
    ";
    mail($user_email, $subj, $msg, $headers, "ISO-8859-1");
    PHP:
     
    GreenHost.Cloud, Jul 28, 2024 IP