This is the first time I’m using PHPMailer and I’m getting error 500 when I send a message through the form on my website.
I also tried port number 587 but I get the same error.
Probably I’ve set something wrong in the server configuration.
What username and password should I put? The credentials of the Microsoft account or just the email and password of the address you want to send emails with?
At this point I am a bit confused.
Also regarding the tls. The person who set up the environment and sent me the credentials, told me to only use TLS version 1.2. Is this something that I can set on the code or that can cause the error 500?
$mail = new PHPMailer(true);
try {
// server configuration
$mail->isSMTP();
$mail->Host = 'smtp.office365.com'; // host server smtp
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // what username? the email address?
$mail->Password = 'password'; // smtp pss
$mail->SMTPSecure = 'tls';
$mail->Port = 25; // tcp port for smtp
// recipients
$mail->setFrom('[email protected]', 'Company Name'); // should this be the same as the username?
$mail->addAddress('[email protected]', 'Mary'); is this and extra email address where I want receive the data
$mail->addAddress('[email protected]', 'Jhon');
// email contents
$mail->isHTML(true); // html email format
$mail->Subject = 'New message from $name';
$mail->Body = $message;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}