Search code examples
phpphpmailer

change sender e-mail address


I am trying to change the sender's email address to some dynamic value.

I am following this question link here and tried the solution, but still the sender's email is the same as SMTP account username.

Here:

        $mail->Host = "smtp.gmail.com";
        $mail->Port = 465; // or 587
        $mail->Username = "[email protected]";
        $mail->Password = 'password';
        $mail->SetFrom($SenderEmail, $SenderName);
        $mail->AddReplyTo($SenderEmail,$SenderName);

But the email header looks like this:

$SenderName <[email protected]>

How can I change this?


Solution

  • No, gmail does not allow you to set arbitrary sender addresses. It does allow you to define a limited number of preset aliases in your account settings, but you can't set random addresses at the point of sending. If you do, it will just ignore it and use your account address instead, as you're seeing. This is mentioned in the PHPMailer troubleshooting guide.