eskimopest
eskimopest

Reputation: 469

php mailer not showing errors but not sending emails

I have a server with email service and im trying to send emails using phpmailer like this:

include('config/class_phpmailer.php');

$email = new PHPMailer();

$email->IsSMTP();
$email->SMTPAuth = true;
$email->Host = 'smtp-mail.outlook.com'; // netcabo
$email->Port = 587; 
$email->SMTPKeepAlive = true;
$email->Username = [email protected];
$email->Password = my_password;
$email->SMTPSecure = 'tls';
$email->From      = [email protected];
$email->FromName  = 'my_name';
$email->Subject   = $subject;
$email->Body      = $message;

// Set the Atatchment
if($attach) {
    $email->AddAttachment($attach);
}
// set the emails to send the message
foreach($emails_to as $mail) {
    $email->addAddress($mail);
}
// send the email
if(!$email->Send()) {
    echo "Message was not sent <br />PHPMailer Error: " . $email->ErrorInfo;
}
else {
    echo "Message has been sent";
}

This works perfectly on localhost but when i upload it into a server, it gives me an error saying: "Message was not sent PHPMailer Error: SMTP connect() failed". So, i've tried changing the host, port, user and pass to my email account from that server and nothing happened. no error, no "message has been sent", nothing... The email wasnt sent either. just a blank page.

What am i doing wrong? thanks in advance.

Upvotes: 0

Views: 2129

Answers (1)

Nebojsa Nebojsa
Nebojsa Nebojsa

Reputation: 1459

If you want to catch an error you can do this

$mail = new PHPMailer(true);
// the true param means it will throw exceptions on errors, which we need to catch

Upvotes: 1

Related Questions