PHP Mailer - SMTP GMAIL AUTHENTICATION

14,136

Solution 1

Gmail re-writes the headers on messages sent through smtp.gmail.com, replacing the FROM address with the gmail address associated with the gmail account that you are using to send the message through. For more info, and a possible workaround, see: http://lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server

Solution 2

It would go into the

$mail->From = "[email protected]"; 
$mail->FromName = "Mailer"; 

Solution 3

Gmail Settings -> Account -> Send email as -> Add another email address you own. Add [email protected] to your gmail account.

http://www.webpagescreenshot.info/img/52022f0a585d18-04883433

Gmail will hold a confirmation process account (will send an email with the code, etc.)

I'm not sure it would work. Try it.

Share:
14,136
Vijay V.
Author by

Vijay V.

Updated on June 04, 2022

Comments

  • Vijay V.
    Vijay V. almost 2 years

    I have problem with the PHP MAILER function. I am using GMAIL SMTP Authentication for sending email and also its working perfectly but i want to set "From" email like "[email protected]" but it doesn't working properly.

    I used below code to set "From" email

    $mail             = new PHPMailer();
    
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host       = "mail.gmail.com"; // SMTP server
    $mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
    $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
    $mail->Username   = "[email protected]";  // GMAIL username
    $mail->Password   = "test@123";  
    
    $mail->SetFrom("[email protected]","Domian");
    

    It's showing me default email [email protected] instead of [email protected]

    Please help me out.

    Thanks in Advance!

  • Jacob Goulden
    Jacob Goulden over 10 years
    If my answer helped or did not just let me know or mark as answer!
  • Vijay V.
    Vijay V. over 10 years
    Getting same problem. I have used this code for setting custom header . $mail->AddCustomHeader('From:[email protected]');
  • Jacob Goulden
    Jacob Goulden over 10 years
    Try $mail->From = "[email protected]"; $mail->FromName = "Mailer";
  • Jacob Goulden
    Jacob Goulden over 10 years
    Why do you set the host twice? also check this solution stackoverflow.com/questions/13574166/…