Hi,
Use PHPMailer, this library is very good. I use it in all my projects.
Library in the
GitHub - PHPMailer/PHPMailer: The classic email sending library for PHP
My function to send an e-mail using PHPMailer.
public function Send_Email_Gmail($address_to, $name_to, $message)
{
try
{
error_reporting(E_STRICT);
date_default_timezone_set('America/Sao_Paulo');
$mail = new phpmailer();
$body = $message;
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = my_user_name_gmail;
$mail->Password = my_password_gmail;
$mail->SetFrom('my_user_name_gmail@gmail.com', utf8_decode('My e-mail'));
$mail->Subject = utf8_decode('send test e-mail');
$mail->AltBody = utf8_decode("To view the message, please use an HTML-compatible email viewer!");
$mail->MsgHTML($body);
$mail->AddAddress($address_to, $name_to);
if($mail->Send()) {
return $mail->ErrorInfo;
} else {
return 'ok';
}
}
catch(Exception $e)
{
return 'Error to send e-mail. Error: ' . $e->getMessage();
}
}