0

I'm making an app which sends an email to users upon registration for activation link with PHPMailer. It is working perfect on localhost but it is not working on live. Search too many solutions online but didn't worked. Tried following things.

1) checking for open ports on server. telnet is connection successfully.

2) installed ssl certificates and tried $mail->SMTPSecure = 'ssl';. Doesn't worked either.

3) Used both Gmail and my (1and1) SMTP servers. both are failing on live.

4) Tried $mail->SMTPSecure = 'tls'; as well as $mail->SMTPSecure = 'ssl';. Neither worked.

5) used plain password in $mail->Password (no special charachters)

When I run code of PHPMailer then it does not display any error, it keeps loading and loading. Library paths arr added correctly (working fine on live). Whole email is being constructed correctly. But when I call $mail->Send(); then it keeps loading forever. If I comment this line then page loads properly (but email does not being sent because send() is commented). My code looks like below.

require_once '../libs/PHPMailer/src/PHPMailer.php';
require_once '../libs/PHPMailer/src/SMTP.php';
require_once '../libs/PHPMailer/src/Exception.php';

 $email = "emailToThisAddress@gmail.com";
 $first_name = "first";
 $last_name = "last";

$mail = new PHPMailer(true);
//Tell PHPMailer to use SMTP
$mail->isSMTP();

try {

$mail->Host = "auth.smtp.1and1.co.uk";
$mail->SMTPDebug = 4;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Port = 587;
$mail->CharSet = 'UTF-8';

$mail->Username = "help@mysite.com";
$mail->Password = "secret";
$mail->addAddress($email, $first_name . " " . $last_name);
$mail->setFrom('help@mysite.com', 'Signup');

$mail->Subject = 'Complete your Sign Up';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$body = HTML_BODY_HERE"";

$mail->MsgHTML($body);
$mail->Send();

} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
Asad ullah
  • 620
  • 2
  • 9
  • 26

0 Answers0