php - Phpmailer working fine in localhost But not in server -
date_default_timezone_set('asia/dubai'); include("classes/class.phpmailer.php"); $mail = new phpmailer(); $body = "this <strong>testing</strong> mail ". date('y-m-d h:i:s'); $mail->issmtp(); // telling class use smtp $mail->smtpdebug = 1; $mail->smtpauth = true; $mail->smtpsecure = "ssl"; $mail->host = "smtp.gmail.com"; $mail->port = 465; $mail->username = 'my@email.com'; $mail->password = '*******'; $mail->setfrom('my@email.com', 'first last'); $mail->addreplyto('my@email.com','first last'); $mail->subject = "phpmailer test subject via smtp (gmail), basic"; $mail->altbody = "to view message, please use html compatible email viewer!"; // optional, comment out , test $mail->msghtml($body); $address = "to@email.com"; // add address here $mail->addaddress($address, "gmail test"); if(!$mail->send()) { echo "mailer error: " . $mail->errorinfo; } else { echo "message sent!"; }
i have script this.its working fine localhost when moving windows or linux servers won't work.i want work on both windows , linux servers.what should do?
error this: smtp -> error: failed connect server: connection timed out (110) smtp error: not connect smtp host. mailer error: smtp error: not connect smtp host.
try using :
require_once ( 'class.phpmailer.php' ); // add path appropriate $mail = new phpmailer(); $mail->issmtp(); // use smtp $mail->host = "smtp.gmail.com"; // sets smtp server $mail->smtpdebug = 2; // 2 enable smtp debug information $mail->smtpauth = true; // enable smtp authentication $mail->smtpsecure = "tls"; //secure conection $mail->port = 587; // set smtp port $mail->username = 'mygmail@gmail.com'; // smtp account username $mail->password = 'mygmailpassword'; // smtp account password $mail->priority = 1; // highest priority - email priority (1 = high, 3 = normal, 5 = low) $mail->charset = 'utf-8'; $mail->encoding = '8bit'; $mail->subject = 'test email using gmail'; $mail->contenttype = 'text/html; charset=utf-8\r\n'; $mail->from = 'mygmail@gmail.com'; $mail->fromname = 'gmail test'; $mail->wordwrap = 900; // rfc 2822 compliant max 998 characters per line $mail->addaddress( $toemail ); // to: $mail->ishtml( true ); $mail->body = $messagehtml; $mail->altbody = $messagetext; $mail->send(); $mail->smtpclose(); if ( $mail->iserror() ) { echo "error<br /><br />"; } else { echo "ok<br /><br />"; }
Comments
Post a Comment