I'm trying to use PHPMailer to send an email using smtp and php. The server I use needs to have this type of connection:
Server name: mail.example.com
Port: 587
User Name: user
Authentication method: Normal Password
Connection Security: STARTTLS
I can seem to get this to work with phpmailer, I've tried several variations but nothing seems to work. here's the code I'm using:
$mail = new phpmailer;
$mail->IsSMTP(); // set mailer to use SMTP
$mail->From = "email@example.com";
$mail->FromName = "example.com";
$mail->Host = "mail.example.com"; // specify main and backup server
$mail->SMTPSecure = 'tls';
$mail->SMTPDebug = 1;
$mail->Port = 587; // set the SMTP port for the server
$mail->SMTPAuth = false;
$mail->Username = "user";
$mail->Password = "password";
$mail->CharSet = 'ISO-8859-1'; // so it interprets foreign characters
$mail->AddAddress("otheremail@example.com", "Other");
$mail->AddReplyTo("email@example.com", "example.com");
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the message body";
$mail->Send(); // send message
This code gives me this error:
SMTP -> ERROR: MAIL not accepted from server: 530 5.7.0 Must issue a STARTTLS command first
SMTP -> ERROR: RCPT not accepted from server: 530 5.7.0 Must issue a STARTTLS command first
SMTP -> ERROR: RCPT not accepted from server: 530 5.7.0 Must issue a STARTTLS command first
SMTP -> ERROR: DATA command not accepted from server: 530 5.7.0 Must issue a STARTTLS command first