Search code examples
phpemailsmtpphpmailer

How to change from email address in smtp php mailer function sendmail()


I am using the below code and I got emails but from email address not coming from setFrom() function. Can anyone help me to set desire from email address in SMTP sendmail() function?

include_once 'Mailer.php'; 

$body = 'TEST, Testing of email.';
$subject = 'Email Demo';
$email = '[email protected]';
$fromEmail = '[email protected]';    

$objMail = new Mailer();
$objMail->mail->AddReplyTo('[email protected]', 'Test 3');
$objMail->mail->SetFrom('[email protected]', 'Test From 1');
$objMail->mail->AddAddress('[email protected]', 'Test 4');
$objMail->mail->IsHTML(true);

$objMail->sendmail($email, 'Test', $subject, $body);

Solution

  • This has been answered many times before. Gmail does not let you set arbitrary from addresses, though you can add a limited number of preconfigured aliases in your account.