2

I am a beginner in PHP programming and i have a problem sending email using localhost (Wamp Server) on windows, I looked dozen of answers on this problem but still unable to solve my problem,Is there any problem in my code?

Here is my code

<?php
/**
 * Created by PhpStorm.
 * User: Farrukh
 * Date: 2/19/2016
 * Time: 5:09 PM
 */


require "PHPMailer-master/PHPMailerAutoload.php";
$mail = new PHPMailer;

$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Username = 'myemail';
$mail->Password = 'mypassword';


$mail->SMTPSecure = 'ssl';
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 465;

$mail->From = 'farrukh@gmail.com';
$mail->FromName = 'FMailer';
$mail->addAddress('myfrien@gmail.com', 'Farrukh');


$mail->WordWrap = 50;
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->isHTML(true);


if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    exit;
}

echo 'Message has been sent';

?>
Farrukh Faizy
  • 1,203
  • 2
  • 18
  • 30
  • `error_reporting(E_ALL);ini_set('display_errors',1);` add it just after ` – Alive to die - Anant Feb 19 '16 at 13:07
  • Add `$mail->SMTPDebug = 2;` Its to enables SMTP debug information (for testing) : 1 = errors and messages / 2 = messages only – ThinkTank Feb 19 '16 at 13:15
  • @Anant It shows nothing ! – Farrukh Faizy Feb 19 '16 at 13:26
  • @ThinkTank It shows me this Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 fl9sm18028559pab.30 - gsmtp 2016-02-19 13:25:31 SMTP Error: Could not authenticate. 2016-02-19 13:25:31 CLIENT -> SERVER: QUIT 2016-02-19 13:25:31 SERVER -> CLIENT: 221 2.0.0 closing connection fl9sm18028559pab.30 - gsmtp 2016-02-19 13:25:31 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. – Farrukh Faizy Feb 19 '16 at 13:27
  • 1
    And so, did you check the 2 links ? support.google and github.com ? Because it seams google has nicely done its job and is giving some good clues =) – ThinkTank Feb 19 '16 at 13:34
  • Yeah i am on it to find – Farrukh Faizy Feb 19 '16 at 13:46
  • You say you're a beginner, but you've based your code on an obsolete gmail example - why not use the up to date one [provided with PHPMailer](https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps)? – Synchro Feb 19 '16 at 13:55
  • Possible duplicate of ["SMTP Error: Could not authenticate" in PHPMailer](http://stackoverflow.com/questions/3949824/smtp-error-could-not-authenticate-in-phpmailer) – Synchro Feb 19 '16 at 13:56

0 Answers0