0

i have used following code to Send mail using PHP

<?php
$sendfrm_name = "Bala";
$sendfrm_id = "xxxxxxxx@gmail.com";
$sendtoname = 'Bala';
$sendto = 'yyyyyy@client.com';
$cc = '';
include("mail/PHPMailerAutoload.php");
include("mail/class.PHPMailer.php");
include("mail/class.smtp.php");
$mail = new PHPMailer;
$mail-> isSMTP();
$mail-> Host = 'smtp.gmail.com'; 
//$mail->SMTPDebug   = 2;
$mail-> SMTPAuth = true;
$mail->smtpConnect = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
$mail-> Username = 'aaasasas@gmail.com';
$mail-> Password = 'pwd';
$mail-> SMTPSecure = 'tls';
$mail-> Port = 587; //587
$mail-> setFrom($sendfrm_id, $sendfrm_name);
$mail-> addAddress($sendto, $sendtoname);
$mail-> addReplyTo($sendto, $sendtoname);
//$mail->addCC($cc);
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = "Test Mail";
$mail->Body = "Name: ".$sendfrm_name ."<br /> Email: ".$sendfrm_id;
if(!$mail->send())
{
    echo "Mailer Error: ".$mail->ErrorInfo;
}
else
{
    echo "1";
}
?>

the above code is working in localhost(php version 5.3) but this same code doesnot work in Server..

Its through failed Error: Mailer Error SMTP() Connection Failed

How to fix this error? and also how to Enable Openssl in linux server?

Rushil K. Pachchigar
  • 1,263
  • 2
  • 21
  • 40
Balakumar B
  • 770
  • 5
  • 17
  • 41

1 Answers1

0

I copy and tested your code, that can work (Both TLS and SSL)

You can enable debug mode to get more detail information.

$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
Calos
  • 1,783
  • 19
  • 28