I am trying to send mail to user when form is submitted. I have the same code in my local host and my server which is aws both running on ubuntu. On my local host I get SMTP connect() failed while it is working fine in my server indicating that the php/smtp settings on my local computer are configured wrong but I can't figure what. Following is the dump of error I got on my local computer.
2014-04-27 18:04:40 CLIENT -> SERVER: EHLO localhost 2014-04-27 18:04:41
SMTP ERROR: EHLO command failed: 220 mx.google.com ESMTP yv5sm29656409pbb.49 - gsmtp 2014-04-27 18:04:41 CLIENT -> SERVER: HELO localhost 2014-04-27 18:04:41
SMTP ERROR: HELO command failed: 552 Command sent before response recieved. 2014-04-27 18:04:41 CLIENT -> SERVER: STARTTLS 2014-04-27 18:04:41
SMTP ERROR: STARTTLS command failed: 2014-04-27 18:04:41
SMTP NOTICE: EOF caught while checking if connected
SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.
Following is my html code
<html>
<body>
<section class="stats" id="signup">
<div class="container" >
<form action="index.php" method="post" class="subscription wow fadeInLeft animated" data-wow-offset="30" data-wow-duration="1.5s" data-wow-delay="0.15s" role="form">
<input type="email" placeholder="Enter email" class="form-control input-box" name="email_address">
<button class="btn btn-primary custom-button red-btn">Sign Up</button>
</form>
</div>
</section>
<?php
if(!isset($_POST['email_address']) || trim($_POST['email_address']) == '')
{
} else {
require '/usr/share/php5/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 1;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'team@compamy.com'; // SMTP username
$mail->Password = '<password>'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'team@compamy.com';
$mail->FromName = 'Team Scaleqa';
$mail->addAddress($_POST['email_address'], ''); // Add a recipient
$mail->addAddress('team@compamy.com'); // Name is optional
$mail->addReplyTo('team@compamy.com', 'Team Scaleqa');
$mail->addCC('team@compamy.com');
$mail->addBCC('team@compamy.com');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Welcome to Company';
$pos = strpos( $_POST['email_address'], "@");
$username = substr($_POST['email_address'], 0, $pos);
$mail->Body = "
Hi
";
//echo $mail->Body;
//$mail->Body = clone $message;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
}
?>
</body>
</html>