0

I have email sharing PHP Code. It's working perfectly to localserver(localhost). I have hosted this code to an online server, but it's not working and there's no response. How to fix this problem? Check my code here..

if(isset($_POST['shareemail'])){
require "php-mailer-master/PHPMailerAutoload.php" ;
$mail = new PHPMailer;
    //$mail->SMTPDebug = 3;                               // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';// smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'funz4m05@gmail.com' ;                // SMTP username
$mail->Password = '******' ;                   // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to
$mail->setFrom(funz4m05@gmail.com, 'mailer');
$mail->addAddress('to@gmail.com');               // Name is optional
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'this subject' ;
$mail->Body    = "<b>html</b>" ; // this is html format
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

    }

?> 
Joseph Cho
  • 3,139
  • 4
  • 17
  • 27
safvan saf
  • 43
  • 7
  • 1
    What does " But Not Working And Any Response" mean? What actually happens? – John Conde Oct 04 '18 at 15:32
  • if you want to send emails using gmail please refer to this: https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps – Sigma Oct 04 '18 at 15:40
  • @John Conde I Have No Getting Any Errors .. and Not Sending the Mail... It is the same After Submit Button.. No Any Changes. – safvan saf Oct 04 '18 at 16:00

1 Answers1

1

Did you forget the ' on $mail->setFrom() or is it just a Typo?

Try

$mail->setFrom('funz4m05@gmail.com', 'mailer');
ivion
  • 545
  • 1
  • 8
  • 12
  • Sorry Made My Mistake My code.. I Already using this... – safvan saf Oct 04 '18 at 15:58
  • I found one difference as stated by Sigma: //Set the hostname of the mail server $mail->Host = 'smtp.gmail.com'; // use // $mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6 – ivion Oct 04 '18 at 16:04
  • not work yet i trying gethostbyname('smtp.gmail.com'); – safvan saf Oct 04 '18 at 18:24