Email not sent via google smtp

I am using the following PHP code to send an email with a predefined mail attachment.



$mail             = new PHPMailer();
$body             = $_POST['message'];
$mail->SMTPAuth   = true;
$mail->Host       = "";
$mail->Port       = 465;
$mail->Username   = "";
$mail->Password   = "****";
$mail->SMTPSecure = 'tls';
$mail->SetFrom('', 'Your name');
$mail->AddReplyTo("","Your name");
$mail->Subject    = "Abstract submission for" .$_POST['fname'];
$mail->AltBody    = $_POST['message'];

if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK){

$address = '';
$mail->AddAddress($address, $name);

if($mail->Send()) {
      echo 'done';
} else {
      echo 'error';



The passwords and other smtp details are correct, but I cannot send mail. What am I doing wrong here? I am using the following html form to post data.

<form id="main-contact-form" class="abstract-form" name="contact-form" method="post" action="/script/submit.php">
<div class="row-fluid">
    <div class="span5">
        <label>First Name</label>
        <input type="text" name='fname' class="input-block-level" required="required" placeholder="Your First Name">
        <label>Last Name</label>
        <input type="text" name='lname' class="input-block-level" required="required" placeholder="Your Last Name">
        <label>Email Address</label>
        <input type="text" name='email' class="input-block-level" required="required" placeholder="Your email address">
        <input type="file" name='file' class="input-block-level" required="required" placeholder="Your Abstract File">
    <div class="span7">
        <textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
<button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>
<p> </p>    


I am getting the following error when I repeat the error information.

The following From address failed: : Called Mail() without being connected



source to share

1 answer

Gmail users can access their account on the official website or use third-party or third-party apps and services. The first party app is, for example, the official Google Gmail app for Android, while Thunderbird and the Windows 8 email client are third-party apps.

Google announced back in April 2014 that it would improve the login security of its services and affect any app that sends usernames and passwords to companies.

The company has proposed switching to OAuth 2.0, but has not implemented it until now.

If you open a new less secure apps page in Google's security settings, you'll notice that Google has disabled access by default.

Note. You only see the page if you are not using Google Apps or have enabled two-factor authentication for your account.

You can flip the switch here to re-enable less secure apps to regain access.

enter image description here



All Articles