I have a site hosted with rackspace and upgraded my site technology from php5.4 to php5.6. Now I can no longer send emails from the site. The worst part is I'm not even getting any errors and the logs show nothing. I am using phpmailer 5.2.14.
Here is my mail script
require 'phpmailer/PHPMailerAutoload.php';
if (isset($_POST['contactForm'])) {
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$body = '
<html>
<body>
<div style="float:left; width:100%; margin:0 0 25px 0; padding:20px; background:#222; text-align:center;">
<div style="display:inline-block; vertical-align:top;">
<a href="http://website.com"><img src="img/logoEmail.png" alt="waesf"></a>
</div>
</div>
<main style="float:left; width:100%; padding:20px;">
<p style="font-family:Arial; font-size:18px;">'.$message.'</p>
</main>
</body>
</html>';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.office365.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'person@email.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->SetFrom('person@email.com', 'Ballpoint Machinist');
$mail->AddAddress('person@email.com', "BPM"); // Add a recipient
$mail->addReplyTo('person@email.com', 'Information');
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $body;
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
When the script runs the site then hangs for a while then gives a says server timed out and nothing else. No php error codes nothing and when I check the logs there are no errors related to my mail code. However this only happens with office 365 when I change the smtp settings to gmail then I at least get php errors on the page.
I have already read a bunch of threads on the subject but I fail to understand. I have also gone through https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting and added the SMTPOptions to exclude ssl but this didn't help.
Im perplexed that I dont get any errors. I have SMTPDebug = 3 and error_reporting(E_ALL).
edit with Willy Pt suggestion. Still doesn't work when script runs server times out.
if (isset($_POST['contactForm'])) {
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$body = '
<html>
<body>
<div style="float:left; width:100%; margin:0 0 25px 0; padding:20px; background:#222; text-align:center;">
<div style="display:inline-block; vertical-align:top;">
<a href="http://website.com"><img src="img/logoEmail.png" alt="Ballpoint Machinist"></a>
</div>
</div>
<main style="float:left; width:100%; padding:20px;">
<p style="font-family:Arial; font-size:18px;">'.$message.'</p>
</main>
</body>
</html>';
$mail = new PHPMailer(true);
// $mail->SMTPDebug = 4; // Enable verbose debug output
try {
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.office365.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'person@person.com'; // SMTP username
$mail->Password = 'test'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->SetFrom('person@person.com', 'Ballpoint Machinist');
$mail->AddAddress('person@person.com', "BPM"); // Add a recipient
$mail->addReplyTo('person@person.com', 'Information');
// $mail->addCC('cc@example.com');
// $mail->addBCC('bcc@example.com');
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $body;
$mail->send();
echo "Message Sent OK\n";
/*if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}*/
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}
}
Can anyone help?