I know this kind of question asked so many times in stackoverflow, but I looked at most of them and the problem still remains.
I'm using phpMailer to send mail from my site using a gmail account.
When I was using this in localhost, everything was fine and mails was sending correctly,
But as long as I uploaded my site in remote server, problem revealed itself.
There's connection timeout(110) error
when I'm using port 465
and smtp.gmail.com
, when I'm trying to use port 587
and tls
there's error too.
Would you please let me know what's wrong?
The host php version is 5.4
.
this is my code:
require_once ("../PHPMailer/class.phpmailer.php");
class mailSender
{
protected $address;
protected $username;
protected $password;
protected $cc;
protected $bcc;
protected $body;
protected $mailer;
public function __construct( $host, $port, $usn, $psw, $isSMTP = true )
{
$this->mailer = new PHPMailer(true);
//$this->mailer->Host = "mail.yourdomain.com"; // SMTP server
$this->mailer->Host = $host; //"smtp.gmail.com"; // sets GMAIL as the SMTP server
$this->mailer->Port = $port; //465; // set the SMTP port for the GMAIL server
if( $isSMTP == true )
{
$this->mailer->IsSMTP();
//$this->mailer->SMTPDebug = 1; // enables SMTP debug information (for testing)
$this->mailer->SMTPAuth = true; // enable SMTP authentication
$this->mailer->SMTPSecure = "ssl"; // sets the prefix to the servier
}
$this->mailer->Username = $usn; //"yourusername@gmail.com"; // GMAIL username
$this->mailer->Password = $psw; //"yourpassword"; // GMAIL password
$this->mailer->CharSet = 'UTF-8';
$this->mailer->IsHTML(true);
//set High priority to prevent going to SPAM folder
$this->mailer->Priority = 1;
$this->mailer->AddCustomHeader("X-MSMail-Priority: High");
$this->mailer->AddCustomHeader("Importance: High");
}//function __construct
public function send( $address, $senderName, $replyAddr, $replyName, $fromAddr, $fromName, $subject, $body, $attachment = false, $cc = false, $bcc = false )
{
try {
//$this->mailer->AddReplyTo( $replyAddr, $replyName);
$this->mailer->AddAddress($address, $senderName);
$this->mailer->SetFrom($fromAddr, $fromName);
$this->mailer->AddReplyTo($replyAddr, $replyName);
$this->mailer->Subject = $subject; //'PHPMailer Test Subject via mail(), advanced';
$this->mailer->AltBody = 'در صورتی که قادر به تماشای محتوای ای-میل نیستید از یک نمایشگر ای-میل تحت HTML استفاده کنید!'; // optional - MsgHTML will create an alternate automatically
$this->mailer->MsgHTML($body);
//$this->mailer->MsgHTML(file_get_contents('contents.html'));
//$this->mailer->AddAttachment('images/phpmailer.gif'); // attachment
//$this->mailer->AddAttachment('images/phpmailer_mini.gif'); // attachment
$send = $this->mailer->Send();
if( $send )
{
return true;
}
else
{
return false;
}
}//try send
catch( Exception $e )
{
return false;
}//catch
}//function Send
}//class mailSender
Thanks in Advance